Skip to content

Commit

Permalink
setup db package for deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
wernst committed Jul 24, 2023
1 parent 127d197 commit 83bc71b
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 138 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ node_modules
!.yarn/sdks
!.yarn/versions

# build artifacts
dist
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"packages/*"
],
"scripts": {
"build:packages": "yarn workspace @triplit/db run build && yarn workspace @triplit/client run build && yarn workspace @triplit/react run build",
"release:packages": "yarn build:packages && yarn workspace @triplit/client run publish-pkg && yarn workspace @triplit/react run publish-pkg && yarn changeset tag",
"build:packages": "yarn workspaces foreach --all run lint",
"release:packages": "yarn workspaces foreach --all run publish-pkg && yarn changeset tag",
"lint": "yarn workspaces foreach --all run lint",
"version": "yarn changeset version && yarn install --mode update-lockfile",
"changeset": "changeset"
Expand Down
18 changes: 0 additions & 18 deletions packages/client/build.cjs

This file was deleted.

6 changes: 2 additions & 4 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
"triplit": "./dist/cli.cjs"
},
"scripts": {
"build": "yarn build:code && yarn build:cli && yarn build:types",
"build": "yarn build:code && yarn build:cli",
"build:cli": "esbuild --bundle --platform=node --target=node14 --outfile=dist/cli.cjs cli/index.ts",
"build:code": "node build.cjs",
"build:types": "tsc --noEmit false --emitDeclarationOnly --declaration --isolatedModules false --outFile dist/index.d.ts && node post-build-types.cjs",
"build:code": "tsc --noEmit false --declaration --baseUrl . --paths null --outDir dist",
"lint": "yarn lint:code && yarn lint:cli",
"lint:code": "tsc",
"lint:cli": "cd ./cli && tsc",
"prepack": "node prepack.cjs",
"publish-pkg": "node ../../scripts/npm-check-version-and-publish.js"
},
"files": [
Expand Down
24 changes: 0 additions & 24 deletions packages/client/post-build-types.cjs

This file was deleted.

46 changes: 0 additions & 46 deletions packages/client/prepack.cjs

This file was deleted.

25 changes: 11 additions & 14 deletions packages/client/src/triplit-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@ import {
Builder,
toBuilder,
CachedIndexedDbStorage as IndexedDbStorage,
} from '@triplit/db';
import { Query } from '@triplit/db/src/query';
import { TripleRow } from '@triplit/db/src/triple-store';
import {
Query,
TripleRow,
Schema,
JSONTypeFromModel,
Model,
Models,
TimestampedObject,
timestampedObjectToPlainObject,
UnTimestampedObject,
} from '@triplit/db/src/schema';
import {
CollectionNameFromModels,
DBTransaction,
ModelFromModels,
} from '@triplit/db/src/db';
import { Mutation } from '@triplit/db/src/mutation';
import { FetchResult } from '@triplit/db/src/collection-query';
import { Timestamp, timestampCompare } from '@triplit/db/src/timestamp';
import { DurableClock } from '@triplit/db/src/clocks/durable-clock';
import { IsAny } from '@triplit/db/src/utility-types';
Mutation,
FetchResult,
Timestamp,
timestampCompare,
DurableClock,
IsAny,
} from '@triplit/db';

export { IndexedDbStorage, MemoryStorage };
type Storage = IndexedDbStorage | MemoryStorage;
Expand Down Expand Up @@ -442,7 +439,7 @@ export class TriplitClient<M extends Models<any, any> | undefined = undefined> {
const jsonResults = new Map(
Array.from(localResults.entries()).map(([key, val]) => [
key,
timestampedObjectToPlainObject(val),
Schema.timestampedObjectToPlainObject(val),
])
);
// @ts-ignore TS not accepting conditional type
Expand Down
7 changes: 4 additions & 3 deletions packages/db/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"name": "@triplit/db",
"type": "module",
"private": true,
"version": "0.0.27",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"build": "yarn build:code && yarn build:types",
"build:code": "esbuild --bundle --minify --platform=browser --target=esnext --outdir=dist src/index.ts",
"build:code": "esbuild --bundle --format=esm --platform=browser --target=esnext --outdir=dist src/index.ts",
"build:types": "tsc --noEmit false --emitDeclarationOnly --declaration --outDir dist",
"lint": "tsc",
"test": "vitest",
"test-coverage": "vitest --coverage",
"test-coverage-ui": "vitest --ui --coverage",
"bench": "vitest bench",
"coverage": "vitest --coverage"
"coverage": "vitest --coverage",
"publish-pkg": "node ../../scripts/npm-check-version-and-publish.js"
},
"files": [
"/dist"
Expand Down
38 changes: 32 additions & 6 deletions packages/db/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
export { default as DB } from './db';
export type { Migration } from './db';
/**
* The fastest path migrating over from our previous pkg setup and including our tuple-database patch is to continue to bundle our source code output.
* For now, it means we need to export our source code output from this file.
* IMO, we'd just transpile each file and keep our directory structure to allow for more selective importing.
* What this means is everything must be imported from "@triplit/db", and not "@triplit/db/dist/query" or something like that.
*/

export { SQLiteTupleStorage as SqliteStorage } from 'tuple-database/storage/SQLiteTupleStorage';
// export { InMemoryTupleStorage as MemoryStorage } from 'tuple-database';
export { default as MemoryStorage } from './storage/memory-btree';
export { default as CachedIndexedDbStorage } from './storage/cached-indexed-db';
export { IndexedDbTupleStorage as IndexedDbStorage } from 'tuple-database/storage/IndexedDbTupleStorage';
export { BrowserTupleStorage as BrowserLocalStorage } from 'tuple-database/storage/BrowserTupleStorage';

export { default as DB } from './db';
export type {
Migration,
CollectionNameFromModels,
DBTransaction,
ModelFromModels,
} from './db';
export { queryResultToJson, or, and } from './query';
export type { Query } from './query';
export type { TripleRow } from './triple-store';
export * as Schema from './schema';
export { default as CollectionQueryBuilder } from './collection-query';
export { default as Builder } from './utils/builder';
export type { toBuilder } from './utils/builder';
export type { CollectionQuery } from './collection-query';
export type {
AttributeDefinition,
CollectionDefinition,
CollectionsDefinition,
JSONTypeFromModel,
Model,
Models,
TimestampedObject,
UnTimestampedObject,
} from './schema';
export type { Mutation } from './mutation';
export { timestampCompare } from './timestamp';
export type { Timestamp } from './timestamp';
export { DurableClock } from './clocks/durable-clock';
export { MemoryClock } from './clocks/memory-clock';
export { default as CollectionQueryBuilder } from './collection-query';
export type { CollectionQuery, FetchResult } from './collection-query';
export { default as Builder } from './utils/builder';
export type { toBuilder } from './utils/builder';
export type { IsAny } from './utility-types';
18 changes: 0 additions & 18 deletions packages/react/build.cjs

This file was deleted.

4 changes: 1 addition & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"typings": "dist/index.d.ts",
"type": "module",
"scripts": {
"build": "yarn build:code && yarn build:types",
"build:code": "node build.cjs",
"build:types": "tsc --noEmit false --emitDeclarationOnly --declaration --baseUrl . --outDir dist",
"build": "tsc --noEmit false --declaration --baseUrl . --paths null --outDir dist",
"lint": "tsc",
"publish-pkg": "node ../../scripts/npm-check-version-and-publish.js"
},
Expand Down

0 comments on commit 83bc71b

Please sign in to comment.