@party-stack/ontology 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/lib/OntologyPullConfig.d.ts +4 -17
- package/lib/OntologyPullConfig.d.ts.map +1 -1
- package/lib/authentication.d.ts +1068 -0
- package/lib/authentication.d.ts.map +1 -0
- package/lib/authentication.js +55 -0
- package/lib/authentication.js.map +1 -0
- package/lib/cli/index.js +19 -45
- package/lib/cli/index.js.map +1 -1
- package/lib/cli/pull.d.ts.map +1 -1
- package/lib/cli/pull.js +16 -29
- package/lib/cli/pull.js.map +1 -1
- package/lib/client.d.ts +11 -0
- package/lib/client.d.ts.map +1 -0
- package/lib/client.js +21 -0
- package/lib/client.js.map +1 -0
- package/lib/examples/blog.d.ts +2 -387
- package/lib/examples/blog.js +1 -353
- package/lib/examples/blog.live-queries.d.ts +1 -1
- package/lib/examples/blog.live-queries.d.ts.map +1 -1
- package/lib/examples/blog.live-queries.js +1 -1
- package/lib/examples/blog.live-queries.js.map +1 -1
- package/lib/examples/generated/collections.d.ts +7 -0
- package/lib/examples/generated/collections.d.ts.map +1 -0
- package/lib/examples/generated/collections.js +12 -0
- package/lib/examples/generated/collections.js.map +1 -0
- package/lib/examples/generated/live.d.ts +2 -2
- package/lib/examples/generated/live.d.ts.map +1 -1
- package/lib/examples/generated/live.js.map +1 -1
- package/lib/http.d.ts +13 -0
- package/lib/http.d.ts.map +1 -0
- package/lib/http.js +29 -0
- package/lib/http.js.map +1 -0
- package/lib/index.d.ts +19 -25
- package/lib/index.js +9 -15
- package/lib/json/index.d.ts +1 -16
- package/lib/json/index.js +2 -132
- package/lib/live/LiveOntology.d.ts +114 -50
- package/lib/live/LiveOntology.d.ts.map +1 -1
- package/lib/live/LiveOntology.js +23 -103
- package/lib/live/LiveOntology.js.map +1 -1
- package/lib/live/actions/createLiveOntologyAction.d.ts +15 -16
- package/lib/live/actions/createLiveOntologyAction.d.ts.map +1 -1
- package/lib/live/actions/createLiveOntologyAction.js +3 -11
- package/lib/live/actions/createLiveOntologyAction.js.map +1 -1
- package/lib/live/actions/types.d.ts +21 -0
- package/lib/live/actions/types.d.ts.map +1 -0
- package/lib/live/attachments/createLiveOntologyAttachments.d.ts +29 -19
- package/lib/live/attachments/createLiveOntologyAttachments.d.ts.map +1 -1
- package/lib/live/attachments/createLiveOntologyAttachments.js +43 -60
- package/lib/live/attachments/createLiveOntologyAttachments.js.map +1 -1
- package/lib/live/attachments/types.d.ts +3 -3
- package/lib/live/index.d.ts +10 -10
- package/lib/live/index.js +5 -6
- package/lib/live/mutators/createReadTx.d.ts +5 -0
- package/lib/live/mutators/createReadTx.d.ts.map +1 -0
- package/lib/live/mutators/createReadTx.js +19 -0
- package/lib/live/mutators/createReadTx.js.map +1 -0
- package/lib/live/mutators/types.d.ts +7 -2
- package/lib/live/mutators/types.d.ts.map +1 -1
- package/lib/live/objects/types.d.ts +6 -0
- package/lib/live/objects/types.d.ts.map +1 -0
- package/lib/live/outbox/types.d.ts +24 -15
- package/lib/live/outbox/types.d.ts.map +1 -1
- package/lib/live/outbox/types.js +1 -11
- package/lib/live/pins.d.ts +51 -0
- package/lib/live/pins.d.ts.map +1 -0
- package/lib/live/pins.js +113 -0
- package/lib/live/pins.js.map +1 -0
- package/lib/live/storageBackend.d.ts +50 -0
- package/lib/live/storageBackend.d.ts.map +1 -0
- package/lib/live/storageBackend.js +42 -0
- package/lib/live/storageBackend.js.map +1 -0
- package/lib/local.d.ts +15 -0
- package/lib/local.d.ts.map +1 -0
- package/lib/local.js +19 -0
- package/lib/local.js.map +1 -0
- package/lib/meta/generated/collections.d.ts +7 -0
- package/lib/meta/generated/collections.d.ts.map +1 -0
- package/lib/meta/generated/collections.js +15 -0
- package/lib/meta/generated/collections.js.map +1 -0
- package/lib/meta/generated/live.d.ts +3 -3
- package/lib/meta/generated/live.d.ts.map +1 -1
- package/lib/meta/generated/live.js +2 -2
- package/lib/meta/generated/live.js.map +1 -1
- package/lib/meta/pull.d.ts +5 -9
- package/lib/meta/pull.d.ts.map +1 -1
- package/lib/meta/pull.js +5 -43
- package/lib/meta/pull.js.map +1 -1
- package/lib/query.d.ts +1 -0
- package/lib/query.js +2 -0
- package/lib/runtime/host.d.ts +35 -0
- package/lib/runtime/host.d.ts.map +1 -0
- package/lib/runtime/host.js +39 -0
- package/lib/runtime/host.js.map +1 -0
- package/lib/runtime/index.d.ts +2 -0
- package/lib/runtime/index.js +1 -0
- package/lib/runtime/live.d.ts +25 -0
- package/lib/runtime/live.d.ts.map +1 -0
- package/lib/runtime/live.js +31 -0
- package/lib/runtime/live.js.map +1 -0
- package/lib/runtime/resource.d.ts +24 -0
- package/lib/runtime/resource.d.ts.map +1 -0
- package/lib/runtime/resource.js +127 -0
- package/lib/runtime/resource.js.map +1 -0
- package/lib/runtime/transactions.d.ts +27 -0
- package/lib/runtime/transactions.d.ts.map +1 -0
- package/lib/runtime/transactions.js +188 -0
- package/lib/runtime/transactions.js.map +1 -0
- package/lib/runtime/view.d.ts +25 -0
- package/lib/runtime/view.d.ts.map +1 -0
- package/lib/runtime/view.js +256 -0
- package/lib/runtime/view.js.map +1 -0
- package/lib/tanstack/collections.d.ts +73 -0
- package/lib/tanstack/collections.d.ts.map +1 -0
- package/lib/tanstack/collections.js +495 -0
- package/lib/tanstack/collections.js.map +1 -0
- package/lib/tanstack/createLocalCollection.d.ts +14 -0
- package/lib/tanstack/createLocalCollection.d.ts.map +1 -0
- package/lib/tanstack/createLocalCollection.js +9 -0
- package/lib/tanstack/createLocalCollection.js.map +1 -0
- package/lib/tanstack/descriptors.d.ts +33 -0
- package/lib/tanstack/descriptors.d.ts.map +1 -0
- package/lib/tanstack/descriptors.js +38 -0
- package/lib/tanstack/descriptors.js.map +1 -0
- package/lib/tanstack/diagnostics.d.ts +23 -0
- package/lib/tanstack/diagnostics.d.ts.map +1 -0
- package/lib/tanstack/diagnostics.js +14 -0
- package/lib/tanstack/diagnostics.js.map +1 -0
- package/lib/tanstack/index.d.ts +6 -0
- package/lib/tanstack/index.js +6 -0
- package/lib/tanstack/localCollection.d.ts +14 -0
- package/lib/tanstack/localCollection.d.ts.map +1 -0
- package/lib/tanstack/localCollection.js +73 -0
- package/lib/tanstack/localCollection.js.map +1 -0
- package/lib/tanstack/subset.d.ts +28 -0
- package/lib/tanstack/subset.d.ts.map +1 -0
- package/lib/tanstack/subset.js +290 -0
- package/lib/tanstack/subset.js.map +1 -0
- package/lib/testing/sqlite.d.ts +40 -0
- package/lib/testing/sqlite.d.ts.map +1 -0
- package/lib/testing/sqlite.js +409 -0
- package/lib/testing/sqlite.js.map +1 -0
- package/lib/testing/sqliteBackend.d.ts +68 -0
- package/lib/testing/sqliteBackend.d.ts.map +1 -0
- package/lib/testing/sqliteBackend.js +34 -0
- package/lib/testing/sqliteBackend.js.map +1 -0
- package/lib/utils/index.d.ts +1 -8
- package/lib/utils/index.js +2 -5
- package/lib/utils/values.d.ts +1 -30
- package/lib/worker.d.ts +19 -0
- package/lib/worker.d.ts.map +1 -0
- package/lib/worker.js +46 -0
- package/lib/worker.js.map +1 -0
- package/package.json +53 -18
- package/lib/cli/format.d.ts +0 -4
- package/lib/cli/format.d.ts.map +0 -1
- package/lib/cli/format.js +0 -19
- package/lib/cli/format.js.map +0 -1
- package/lib/cli/generate.d.ts +0 -10
- package/lib/cli/generate.d.ts.map +0 -1
- package/lib/cli/generate.js +0 -108
- package/lib/cli/generate.js.map +0 -1
- package/lib/examples/blog.d.ts.map +0 -1
- package/lib/examples/blog.js.map +0 -1
- package/lib/generate/builders.d.ts +0 -12
- package/lib/generate/builders.d.ts.map +0 -1
- package/lib/generate/builders.js +0 -58
- package/lib/generate/builders.js.map +0 -1
- package/lib/generate/constants.d.ts +0 -5
- package/lib/generate/constants.d.ts.map +0 -1
- package/lib/generate/constants.js +0 -28
- package/lib/generate/constants.js.map +0 -1
- package/lib/generate/index.d.ts +0 -6
- package/lib/generate/index.js +0 -6
- package/lib/generate/live.d.ts +0 -12
- package/lib/generate/live.d.ts.map +0 -1
- package/lib/generate/live.js +0 -48
- package/lib/generate/live.js.map +0 -1
- package/lib/generate/ontology.d.ts +0 -8
- package/lib/generate/ontology.d.ts.map +0 -1
- package/lib/generate/ontology.js +0 -501
- package/lib/generate/ontology.js.map +0 -1
- package/lib/generate/types.d.ts +0 -18
- package/lib/generate/types.d.ts.map +0 -1
- package/lib/generate/types.js +0 -216
- package/lib/generate/types.js.map +0 -1
- package/lib/generate/utils/buildJsDocs.d.ts +0 -10
- package/lib/generate/utils/buildJsDocs.d.ts.map +0 -1
- package/lib/generate/utils/buildJsDocs.js +0 -16
- package/lib/generate/utils/buildJsDocs.js.map +0 -1
- package/lib/infer.d.ts +0 -223
- package/lib/infer.d.ts.map +0 -1
- package/lib/infer.js +0 -14
- package/lib/infer.js.map +0 -1
- package/lib/installation/createMetaOntologyConfiguration.d.ts +0 -10
- package/lib/installation/createMetaOntologyConfiguration.d.ts.map +0 -1
- package/lib/installation/createMetaOntologyConfiguration.js +0 -16
- package/lib/installation/createMetaOntologyConfiguration.js.map +0 -1
- package/lib/installation/createOntologyBackendInstallation.d.ts +0 -5
- package/lib/installation/createOntologyBackendInstallation.d.ts.map +0 -1
- package/lib/installation/createOntologyBackendInstallation.js +0 -221
- package/lib/installation/createOntologyBackendInstallation.js.map +0 -1
- package/lib/installation/index.d.ts +0 -4
- package/lib/installation/index.js +0 -3
- package/lib/installation/types.d.ts +0 -94
- package/lib/installation/types.d.ts.map +0 -1
- package/lib/ir/generated/builders.d.ts +0 -380
- package/lib/ir/generated/builders.d.ts.map +0 -1
- package/lib/ir/generated/builders.js +0 -186
- package/lib/ir/generated/builders.js.map +0 -1
- package/lib/ir/generated/constants.d.ts +0 -265
- package/lib/ir/generated/constants.d.ts.map +0 -1
- package/lib/ir/generated/constants.js +0 -165
- package/lib/ir/generated/constants.js.map +0 -1
- package/lib/ir/generated/types.d.ts +0 -413
- package/lib/ir/generated/types.d.ts.map +0 -1
- package/lib/ir/index.d.ts +0 -4
- package/lib/ir/index.js +0 -3
- package/lib/ir/schema.d.ts +0 -2246
- package/lib/ir/schema.d.ts.map +0 -1
- package/lib/ir/schema.js +0 -1187
- package/lib/ir/schema.js.map +0 -1
- package/lib/ir/validate.d.ts +0 -8
- package/lib/ir/validate.d.ts.map +0 -1
- package/lib/ir/validate.js +0 -623
- package/lib/ir/validate.js.map +0 -1
- package/lib/json/index.d.ts.map +0 -1
- package/lib/json/index.js.map +0 -1
- package/lib/lenses.d.ts +0 -21
- package/lib/lenses.d.ts.map +0 -1
- package/lib/lenses.js +0 -110
- package/lib/lenses.js.map +0 -1
- package/lib/live/OntologyBackendAdapter.d.ts +0 -104
- package/lib/live/OntologyBackendAdapter.d.ts.map +0 -1
- package/lib/live/OntologyBackendAdapter.js +0 -1
- package/lib/live/actions/createLiveOntologyActions.d.ts +0 -28
- package/lib/live/actions/createLiveOntologyActions.d.ts.map +0 -1
- package/lib/live/actions/createLiveOntologyActions.js +0 -139
- package/lib/live/actions/createLiveOntologyActions.js.map +0 -1
- package/lib/live/actions/prepareActionParameters.d.ts +0 -19
- package/lib/live/actions/prepareActionParameters.d.ts.map +0 -1
- package/lib/live/actions/prepareActionParameters.js +0 -213
- package/lib/live/actions/prepareActionParameters.js.map +0 -1
- package/lib/live/attachments/attachmentSources.d.ts +0 -10
- package/lib/live/attachments/attachmentSources.d.ts.map +0 -1
- package/lib/live/attachments/attachmentSources.js +0 -64
- package/lib/live/attachments/attachmentSources.js.map +0 -1
- package/lib/live/attachments/unsupportedOntologyAttachmentsAdapter.d.ts +0 -5
- package/lib/live/attachments/unsupportedOntologyAttachmentsAdapter.d.ts.map +0 -1
- package/lib/live/attachments/unsupportedOntologyAttachmentsAdapter.js +0 -6
- package/lib/live/attachments/unsupportedOntologyAttachmentsAdapter.js.map +0 -1
- package/lib/live/expression.d.ts +0 -24
- package/lib/live/expression.d.ts.map +0 -1
- package/lib/live/expression.js +0 -160
- package/lib/live/expression.js.map +0 -1
- package/lib/live/mutators/OntologyEdits.d.ts +0 -15
- package/lib/live/mutators/OntologyEdits.d.ts.map +0 -1
- package/lib/live/mutators/OntologyEdits.js +0 -65
- package/lib/live/mutators/OntologyEdits.js.map +0 -1
- package/lib/live/mutators/createMutatorTx.d.ts +0 -11
- package/lib/live/mutators/createMutatorTx.d.ts.map +0 -1
- package/lib/live/mutators/createMutatorTx.js +0 -61
- package/lib/live/mutators/createMutatorTx.js.map +0 -1
- package/lib/live/mutators/runOptimisticAction.d.ts +0 -19
- package/lib/live/mutators/runOptimisticAction.d.ts.map +0 -1
- package/lib/live/mutators/runOptimisticAction.js +0 -30
- package/lib/live/mutators/runOptimisticAction.js.map +0 -1
- package/lib/live/objects/OntologyObject.d.ts +0 -4
- package/lib/live/objects/OntologyObject.d.ts.map +0 -1
- package/lib/live/objects/OntologyObject.js +0 -1
- package/lib/live/objects/createLiveOntologyObjectCollection.d.ts +0 -17
- package/lib/live/objects/createLiveOntologyObjectCollection.d.ts.map +0 -1
- package/lib/live/objects/createLiveOntologyObjectCollection.js +0 -69
- package/lib/live/objects/createLiveOntologyObjectCollection.js.map +0 -1
- package/lib/live/objects/ontologyObjectCollectionId.d.ts +0 -4
- package/lib/live/objects/ontologyObjectCollectionId.d.ts.map +0 -1
- package/lib/live/objects/ontologyObjectCollectionId.js +0 -8
- package/lib/live/objects/ontologyObjectCollectionId.js.map +0 -1
- package/lib/live/outbox/createOntologyOutbox.d.ts +0 -23
- package/lib/live/outbox/createOntologyOutbox.d.ts.map +0 -1
- package/lib/live/outbox/createOntologyOutbox.js +0 -292
- package/lib/live/outbox/createOntologyOutbox.js.map +0 -1
- package/lib/live/outbox/leaderExecutor.d.ts +0 -20
- package/lib/live/outbox/leaderExecutor.d.ts.map +0 -1
- package/lib/live/outbox/leaderExecutor.js +0 -130
- package/lib/live/outbox/leaderExecutor.js.map +0 -1
- package/lib/live/outbox/outboxService.d.ts +0 -7
- package/lib/live/outbox/outboxService.d.ts.map +0 -1
- package/lib/live/outbox/outboxService.js +0 -68
- package/lib/live/outbox/outboxService.js.map +0 -1
- package/lib/live/outbox/projectionManager.d.ts +0 -31
- package/lib/live/outbox/projectionManager.d.ts.map +0 -1
- package/lib/live/outbox/projectionManager.js +0 -127
- package/lib/live/outbox/projectionManager.js.map +0 -1
- package/lib/live/outbox/repository.d.ts +0 -31
- package/lib/live/outbox/repository.d.ts.map +0 -1
- package/lib/live/outbox/repository.js +0 -196
- package/lib/live/outbox/repository.js.map +0 -1
- package/lib/live/outbox/service.d.ts +0 -61
- package/lib/live/outbox/service.d.ts.map +0 -1
- package/lib/live/outbox/service.js +0 -6
- package/lib/live/outbox/service.js.map +0 -1
- package/lib/live/outbox/types.js.map +0 -1
- package/lib/live/waitForCollectionReady.d.ts +0 -5
- package/lib/live/waitForCollectionReady.d.ts.map +0 -1
- package/lib/live/waitForCollectionReady.js +0 -49
- package/lib/live/waitForCollectionReady.js.map +0 -1
- package/lib/meta/createLocalMetaOntologyBackendAdapter.d.ts +0 -7
- package/lib/meta/createLocalMetaOntologyBackendAdapter.d.ts.map +0 -1
- package/lib/meta/createLocalMetaOntologyBackendAdapter.js +0 -44
- package/lib/meta/createLocalMetaOntologyBackendAdapter.js.map +0 -1
- package/lib/meta/generated/constants.d.ts +0 -265
- package/lib/meta/generated/constants.d.ts.map +0 -1
- package/lib/meta/generated/constants.js +0 -165
- package/lib/meta/generated/constants.js.map +0 -1
- package/lib/meta/generated/types.d.ts +0 -417
- package/lib/meta/generated/types.d.ts.map +0 -1
- package/lib/meta/generated/types.js +0 -1
- package/lib/meta/ontology.d.ts +0 -26
- package/lib/meta/ontology.d.ts.map +0 -1
- package/lib/meta/ontology.js +0 -111
- package/lib/meta/ontology.js.map +0 -1
- package/lib/utils/links.d.ts +0 -50
- package/lib/utils/links.d.ts.map +0 -1
- package/lib/utils/links.js +0 -13
- package/lib/utils/links.js.map +0 -1
- package/lib/utils/paths.d.ts +0 -6
- package/lib/utils/paths.d.ts.map +0 -1
- package/lib/utils/paths.js +0 -42
- package/lib/utils/paths.js.map +0 -1
- package/lib/utils/provide.d.ts +0 -4
- package/lib/utils/provide.d.ts.map +0 -1
- package/lib/utils/provide.js +0 -9
- package/lib/utils/provide.js.map +0 -1
- package/lib/utils/targets.d.ts +0 -37
- package/lib/utils/targets.d.ts.map +0 -1
- package/lib/utils/targets.js +0 -1
- package/lib/utils/typeNames.d.ts +0 -28
- package/lib/utils/typeNames.d.ts.map +0 -1
- package/lib/utils/typeNames.js +0 -1
- package/lib/utils/types.d.ts +0 -12
- package/lib/utils/types.d.ts.map +0 -1
- package/lib/utils/types.js +0 -48
- package/lib/utils/types.js.map +0 -1
- package/lib/utils/uncertain.d.ts +0 -11
- package/lib/utils/uncertain.d.ts.map +0 -1
- package/lib/utils/uncertain.js +0 -14
- package/lib/utils/uncertain.js.map +0 -1
- package/lib/utils/validation.d.ts +0 -7
- package/lib/utils/validation.d.ts.map +0 -1
- package/lib/utils/validation.js +0 -1
- package/lib/utils/values.d.ts.map +0 -1
- /package/lib/{installation → live/actions}/types.js +0 -0
- /package/lib/{ir/generated → live/objects}/types.js +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { makeStorageOntologyBackend } from "../live/storageBackend.js";
|
|
2
|
+
import { BackendError } from "@party-stack/ontology-backend";
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
import { byteIO, byteSource } from "@party-stack/ontology-storage/blobs";
|
|
5
|
+
import * as SQLite from "@party-stack/sql-ontology-storage/sqlite";
|
|
6
|
+
//#region src/testing/sqliteBackend.ts
|
|
7
|
+
const makeSQLiteTestBackend = Effect.fnUntraced(function* (options) {
|
|
8
|
+
const namespace = options.name ?? "sqlite";
|
|
9
|
+
const external = options.attachmentStorage?.external;
|
|
10
|
+
const storage = yield* SQLite.makeStorage(options.database, {
|
|
11
|
+
namespace,
|
|
12
|
+
attachmentBytesRetentionMode: "authoritative",
|
|
13
|
+
bytes: external ? {
|
|
14
|
+
read: (key) => Effect.tryPromise(() => external.bytes.read(key)).pipe(Effect.map((value) => value === void 0 ? void 0 : byteSource(value))),
|
|
15
|
+
write: (key, blob) => byteIO((signal) => external.bytes.write(key, blob, signal)),
|
|
16
|
+
delete: (key) => Effect.tryPromise(() => external.bytes.delete(key))
|
|
17
|
+
} : void 0
|
|
18
|
+
});
|
|
19
|
+
return yield* makeStorageOntologyBackend({
|
|
20
|
+
...options,
|
|
21
|
+
...storage,
|
|
22
|
+
namespace
|
|
23
|
+
});
|
|
24
|
+
}, Effect.mapError((cause) => cause instanceof BackendError ? cause : new BackendError({
|
|
25
|
+
operation: "sqlite.open",
|
|
26
|
+
kind: "Unavailable",
|
|
27
|
+
message: "SQLite storage failed.",
|
|
28
|
+
retryable: false,
|
|
29
|
+
cause
|
|
30
|
+
})));
|
|
31
|
+
//#endregion
|
|
32
|
+
export { makeSQLiteTestBackend };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=sqliteBackend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqliteBackend.js","names":[],"sources":["../../src/testing/sqliteBackend.ts"],"sourcesContent":["import { BackendError } from \"@party-stack/ontology-backend\";\nimport { byteIO, byteSource, type ByteInput } from \"@party-stack/ontology-storage/blobs\";\nimport * as SQLite from \"@party-stack/sql-ontology-storage/sqlite\";\nimport { Effect } from \"effect\";\nimport { makeStorageOntologyBackend, type StorageOntologyBackendOptions } from \"../live/storageBackend.js\";\nexport interface SQLiteDatabase extends SQLite.SQLiteDatabase {\n prepare(sql: string): SQLite.SQLiteStatement & { get(...parameters: unknown[]): unknown };\n transaction(body: () => void): () => void;\n}\nexport interface SQLiteAttachmentBytesStore {\n write(id: string, blob: ByteInput, signal?: AbortSignal): Promise<void>;\n read(id: string): Promise<ByteInput | undefined>;\n delete(id: string): Promise<void>;\n}\nexport interface SQLiteAttachmentStorageOptions {\n external?: { bytes: SQLiteAttachmentBytesStore };\n}\ntype Options = Omit<StorageOntologyBackendOptions, \"namespace\" | \"tables\" | \"blobs\"> & {\n database: SQLiteDatabase;\n name?: string;\n attachmentStorage?: SQLiteAttachmentStorageOptions;\n};\nexport const makeSQLiteTestBackend = Effect.fnUntraced(\n function* (options: Options) {\n const namespace = options.name ?? \"sqlite\";\n const external = options.attachmentStorage?.external;\n const storage = yield* SQLite.makeStorage(options.database, {\n namespace,\n attachmentBytesRetentionMode: \"authoritative\",\n bytes: external\n ? {\n read: (key) =>\n Effect.tryPromise(() => external.bytes.read(key)).pipe(\n Effect.map((value) => (value === undefined ? undefined : byteSource(value)))\n ),\n write: (key, blob) => byteIO((signal) => external.bytes.write(key, blob, signal)),\n delete: (key) => Effect.tryPromise(() => external.bytes.delete(key)),\n }\n : undefined,\n });\n return yield* makeStorageOntologyBackend({ ...options, ...storage, namespace });\n },\n Effect.mapError((cause) =>\n cause instanceof BackendError\n ? cause\n : new BackendError({\n operation: \"sqlite.open\",\n kind: \"Unavailable\",\n message: \"SQLite storage failed.\",\n retryable: false,\n cause,\n })\n )\n);\n"],"mappings":";;;;;;AAsBA,MAAa,wBAAwB,OAAO,WACxC,WAAW,SAAkB;CACzB,MAAM,YAAY,QAAQ,QAAQ;CAClC,MAAM,WAAW,QAAQ,mBAAmB;CAC5C,MAAM,UAAU,OAAO,OAAO,YAAY,QAAQ,UAAU;EACxD;EACA,8BAA8B;EAC9B,OAAO,WACD;GACI,OAAO,QACH,OAAO,iBAAiB,SAAS,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,KAC9C,OAAO,KAAK,UAAW,UAAU,KAAA,IAAY,KAAA,IAAY,WAAW,KAAK,CAAE,CAC/E;GACJ,QAAQ,KAAK,SAAS,QAAQ,WAAW,SAAS,MAAM,MAAM,KAAK,MAAM,MAAM,CAAC;GAChF,SAAS,QAAQ,OAAO,iBAAiB,SAAS,MAAM,OAAO,GAAG,CAAC;EACvE,IACA,KAAA;CACV,CAAC;CACD,OAAO,OAAO,2BAA2B;EAAE,GAAG;EAAS,GAAG;EAAS;CAAU,CAAC;AAClF,GACA,OAAO,UAAU,UACb,iBAAiB,eACX,QACA,IAAI,aAAa;CACb,WAAW;CACX,MAAM;CACN,SAAS;CACT,WAAW;CACX;AACJ,CAAC,CACX,CACJ"}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { ValidationIssue } from "./validation.js";
|
|
3
|
-
import { OntologyActionParameterTarget, OntologyActionParametersTarget, OntologyAttachmentBindingTarget, OntologyAttachmentCreateTarget, OntologyObjectPropertyTarget, OntologyObjectTarget, OntologyQueryFunctionParametersTarget, OntologyQueryFunctionReturnTarget, OntologyTypeTarget } from "./targets.js";
|
|
4
|
-
import { Uncertain, certain, uncertain } from "./uncertain.js";
|
|
5
|
-
import { LinkHopLink, LinkHopName, LinkHopTargetObjectType, isLinkHopFromForeignKeySource, resolveLinkHop } from "./links.js";
|
|
6
|
-
import { getAtPath, setAtPath, unsetAtPath } from "./paths.js";
|
|
7
|
-
import { getTargetValueType, resolveType, unwrapType, unwrapValueType } from "./types.js";
|
|
8
|
-
export { LinkHopLink, LinkHopName, LinkHopTargetObjectType, OntologyActionParameterTarget, OntologyActionParametersTarget, OntologyAttachmentBindingTarget, OntologyAttachmentCreateTarget, OntologyObjectPropertyTarget, OntologyObjectTarget, OntologyQueryFunctionParametersTarget, OntologyQueryFunctionReturnTarget, OntologyTypeTarget, type Result, Uncertain, type Union, type ValidationIssue, type attachment, certain, type date, type double, type float, type geopoint, getAtPath, getTargetValueType, type integer, isLinkHopFromForeignKeySource, resolveLinkHop, resolveType, setAtPath, type timestamp, uncertain, unsetAtPath, unwrapType, unwrapValueType };
|
|
1
|
+
export * from "@party-stack/ontology-spec/utils";
|
package/lib/utils/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { getAtPath, setAtPath, unsetAtPath } from "./paths.js";
|
|
4
|
-
import { certain, uncertain } from "./uncertain.js";
|
|
5
|
-
export { certain, getAtPath, getTargetValueType, isLinkHopFromForeignKeySource, resolveLinkHop, resolveType, setAtPath, uncertain, unsetAtPath, unwrapType, unwrapValueType };
|
|
1
|
+
export * from "@party-stack/ontology-spec/utils";
|
|
2
|
+
export {};
|
package/lib/utils/values.d.ts
CHANGED
|
@@ -1,30 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/utils/values.d.ts
|
|
3
|
-
export type integer = number;
|
|
4
|
-
export type float = number;
|
|
5
|
-
export type double = number;
|
|
6
|
-
export type geopoint = {
|
|
7
|
-
lat: double;
|
|
8
|
-
lon: double;
|
|
9
|
-
};
|
|
10
|
-
export type date = Temporal.PlainDate;
|
|
11
|
-
export type timestamp = Temporal.Instant;
|
|
12
|
-
export type Union<T extends Record<string, unknown>> = { [K in keyof T]: {
|
|
13
|
-
kind: K;
|
|
14
|
-
value: T[K];
|
|
15
|
-
}; }[keyof T];
|
|
16
|
-
export type Result<T, E> = Union<{
|
|
17
|
-
ok: T;
|
|
18
|
-
err: E;
|
|
19
|
-
}>;
|
|
20
|
-
export type attachment<Type extends string = string> = {
|
|
21
|
-
id: string;
|
|
22
|
-
type?: Type;
|
|
23
|
-
source?: {
|
|
24
|
-
objectType: string;
|
|
25
|
-
primaryKey: string | number;
|
|
26
|
-
property: string;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
//#endregion
|
|
30
|
-
//# sourceMappingURL=values.d.ts.map
|
|
1
|
+
export type * from "@party-stack/ontology-spec/values";
|
package/lib/worker.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CreateLiveOntologyOpts } from "./live/LiveOntology.js";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
//#region src/worker.d.ts
|
|
4
|
+
export interface WorkerClientOptions {
|
|
5
|
+
/** Worker transport startup deadline; does not limit ontology/backend initialization. */
|
|
6
|
+
readonly connectionTimeoutMs?: number;
|
|
7
|
+
readonly ontology?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const workerClient: (spawn: () => Worker | SharedWorker | MessagePort, options?: WorkerClientOptions | undefined) => Effect.Effect<import("@party-stack/ontology-server/rpc").OntologyServerClient, import("@party-stack/ontology-backend").BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, import("effect/Scope").Scope>;
|
|
10
|
+
/** Complete non-Effect setup for a single private browser replica. Native server
|
|
11
|
+
* composition uses ontology-server/rpc/worker directly with an Effect entrypoint.
|
|
12
|
+
*/
|
|
13
|
+
export declare function serveOntologyWorker<Context extends Record<string, unknown> = Record<string, unknown>>(options: CreateLiveOntologyOpts<Context> & {
|
|
14
|
+
readonly enableRealtime?: boolean;
|
|
15
|
+
}): {
|
|
16
|
+
cleanup: () => Promise<undefined>;
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","names":[],"sources":["../src/worker.ts"],"mappings":";;;iBAaiB;;WAEJ;WACA;;qBAYA,eAAY,aACR,SAAS,eAAe,aAAW,UAAA,oCAAA,OAAA,kDAAA,8DAAA,wXAAA;;;;wBAUpC,oBAAoB,gBAAgB,0BAA0B,yBAC1E,SAAS,uBAAuB;WAAsB;;EAyB7C,eAAO"}
|
package/lib/worker.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { makeOntologyResource } from "./runtime/resource.js";
|
|
2
|
+
import { MemoryRuntime, Runtimes } from "@party-stack/runtime";
|
|
3
|
+
import { Effect, Fiber } from "effect";
|
|
4
|
+
import { TraceRecording } from "@party-stack/runtime/tracing";
|
|
5
|
+
import * as BrowserWorker from "@effect/platform-browser/BrowserWorker";
|
|
6
|
+
import * as BrowserWorkerRunner from "@effect/platform-browser/BrowserWorkerRunner";
|
|
7
|
+
import { makeOntologyServer } from "@party-stack/ontology-server";
|
|
8
|
+
import { makeOntologyWorkerClient, serveOntologyWorker as serveOntologyWorker$1 } from "@party-stack/ontology-server/rpc/worker";
|
|
9
|
+
//#region src/worker.ts
|
|
10
|
+
/** The factory runs only when the view opens. Vite can still discover a literal worker constructor. */
|
|
11
|
+
const acquireWorker = (spawn) => Effect.acquireRelease(Effect.sync(spawn), (worker) => Effect.sync(() => {
|
|
12
|
+
if ("port" in worker) worker.port.close();
|
|
13
|
+
else if ("terminate" in worker) worker.terminate();
|
|
14
|
+
else worker.close();
|
|
15
|
+
}));
|
|
16
|
+
const workerClient = Effect.fnUntraced(function* (spawn, options) {
|
|
17
|
+
const worker = yield* acquireWorker(spawn);
|
|
18
|
+
return yield* makeOntologyWorkerClient(options).pipe(Effect.provide(BrowserWorker.layer(() => worker)));
|
|
19
|
+
});
|
|
20
|
+
/** Complete non-Effect setup for a single private browser replica. Native server
|
|
21
|
+
* composition uses ontology-server/rpc/worker directly with an Effect entrypoint.
|
|
22
|
+
*/
|
|
23
|
+
function serveOntologyWorker(options) {
|
|
24
|
+
const server = Effect.gen(function* () {
|
|
25
|
+
const resource = yield* makeOntologyResource({
|
|
26
|
+
...options,
|
|
27
|
+
traceRecording: options.traceRecording ?? "live"
|
|
28
|
+
});
|
|
29
|
+
return yield* makeOntologyServer({
|
|
30
|
+
enableRealtime: options.enableRealtime,
|
|
31
|
+
kind: "replica",
|
|
32
|
+
replica: resource.replica,
|
|
33
|
+
backend: resource.backend,
|
|
34
|
+
ir: resource.ir,
|
|
35
|
+
traces: resource.traces,
|
|
36
|
+
dangerouslyAllowInternalAccess: true
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
const work = serveOntologyWorker$1(server).pipe(Effect.flatMap(Fiber.join), Effect.scoped, Effect.provideService(TraceRecording, options.traceRecording ?? "live"), Effect.provide(options.runtime ?? Runtimes.layer(MemoryRuntime.layer)), Effect.provide(BrowserWorkerRunner.layer));
|
|
40
|
+
const fiber = Effect.runFork(work);
|
|
41
|
+
return { cleanup: () => Effect.runPromise(Fiber.interrupt(fiber)).then(() => void 0) };
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { serveOntologyWorker, workerClient };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","names":["serveNativeOntologyWorker"],"sources":["../src/worker.ts"],"sourcesContent":["import * as BrowserWorker from \"@effect/platform-browser/BrowserWorker\";\nimport * as BrowserWorkerRunner from \"@effect/platform-browser/BrowserWorkerRunner\";\nimport { makeOntologyServer } from \"@party-stack/ontology-server\";\nimport {\n makeOntologyWorkerClient,\n serveOntologyWorker as serveNativeOntologyWorker,\n} from \"@party-stack/ontology-server/rpc/worker\";\nimport { MemoryRuntime, Runtimes } from \"@party-stack/runtime\";\nimport { TraceRecording } from \"@party-stack/runtime/tracing\";\nimport { Effect, Fiber } from \"effect\";\nimport { makeOntologyResource } from \"./runtime/resource.js\";\nimport type { CreateLiveOntologyOpts } from \"./live/LiveOntology.js\";\n\nexport interface WorkerClientOptions {\n /** Worker transport startup deadline; does not limit ontology/backend initialization. */\n readonly connectionTimeoutMs?: number;\n readonly ontology?: string;\n}\n\n/** The factory runs only when the view opens. Vite can still discover a literal worker constructor. */\nconst acquireWorker = (spawn: () => Worker | SharedWorker | MessagePort) =>\n Effect.acquireRelease(Effect.sync(spawn), (worker) =>\n Effect.sync(() => {\n if (\"port\" in worker) worker.port.close();\n else if (\"terminate\" in worker) worker.terminate();\n else worker.close();\n })\n );\nexport const workerClient = Effect.fnUntraced(function* (\n spawn: () => Worker | SharedWorker | MessagePort,\n options?: WorkerClientOptions\n) {\n const worker = yield* acquireWorker(spawn);\n return yield* makeOntologyWorkerClient(options).pipe(Effect.provide(BrowserWorker.layer(() => worker)));\n});\n\n/** Complete non-Effect setup for a single private browser replica. Native server\n * composition uses ontology-server/rpc/worker directly with an Effect entrypoint.\n */\nexport function serveOntologyWorker<Context extends Record<string, unknown> = Record<string, unknown>>(\n options: CreateLiveOntologyOpts<Context> & { readonly enableRealtime?: boolean }\n) {\n const server = Effect.gen(function* () {\n const resource = yield* makeOntologyResource({\n ...options,\n traceRecording: options.traceRecording ?? \"live\",\n });\n return yield* makeOntologyServer({\n enableRealtime: options.enableRealtime,\n kind: \"replica\",\n replica: resource.replica,\n backend: resource.backend,\n ir: resource.ir,\n traces: resource.traces,\n dangerouslyAllowInternalAccess: true,\n });\n });\n const work = serveNativeOntologyWorker(server).pipe(\n Effect.flatMap(Fiber.join),\n Effect.scoped,\n Effect.provideService(TraceRecording, options.traceRecording ?? \"live\"),\n Effect.provide(options.runtime ?? Runtimes.layer(MemoryRuntime.layer)),\n Effect.provide(BrowserWorkerRunner.layer)\n );\n const fiber = Effect.runFork(work);\n return { cleanup: () => Effect.runPromise(Fiber.interrupt(fiber)).then(() => undefined) };\n}\n"],"mappings":";;;;;;;;;;AAoBA,MAAM,iBAAiB,UACnB,OAAO,eAAe,OAAO,KAAK,KAAK,IAAI,WACvC,OAAO,WAAW;CACd,IAAI,UAAU,QAAQ,OAAO,KAAK,MAAM;MACnC,IAAI,eAAe,QAAQ,OAAO,UAAU;MAC5C,OAAO,MAAM;AACtB,CAAC,CACL;AACJ,MAAa,eAAe,OAAO,WAAW,WAC1C,OACA,SACF;CACE,MAAM,SAAS,OAAO,cAAc,KAAK;CACzC,OAAO,OAAO,yBAAyB,OAAO,CAAC,CAAC,KAAK,OAAO,QAAQ,cAAc,YAAY,MAAM,CAAC,CAAC;AAC1G,CAAC;;;;AAKD,SAAgB,oBACZ,SACF;CACE,MAAM,SAAS,OAAO,IAAI,aAAa;EACnC,MAAM,WAAW,OAAO,qBAAqB;GACzC,GAAG;GACH,gBAAgB,QAAQ,kBAAkB;EAC9C,CAAC;EACD,OAAO,OAAO,mBAAmB;GAC7B,gBAAgB,QAAQ;GACxB,MAAM;GACN,SAAS,SAAS;GAClB,SAAS,SAAS;GAClB,IAAI,SAAS;GACb,QAAQ,SAAS;GACjB,gCAAgC;EACpC,CAAC;CACL,CAAC;CACD,MAAM,OAAOA,sBAA0B,MAAM,CAAC,CAAC,KAC3C,OAAO,QAAQ,MAAM,IAAI,GACzB,OAAO,QACP,OAAO,eAAe,gBAAgB,QAAQ,kBAAkB,MAAM,GACtE,OAAO,QAAQ,QAAQ,WAAW,SAAS,MAAM,cAAc,KAAK,CAAC,GACrE,OAAO,QAAQ,oBAAoB,KAAK,CAC5C;CACA,MAAM,QAAQ,OAAO,QAAQ,IAAI;CACjC,OAAO,EAAE,eAAe,OAAO,WAAW,MAAM,UAAU,KAAK,CAAC,CAAC,CAAC,WAAW,KAAA,CAAS,EAAE;AAC5F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@party-stack/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"bin": {
|
|
5
5
|
"ontology": "./lib/cli/index.js"
|
|
6
6
|
},
|
|
@@ -23,42 +23,77 @@
|
|
|
23
23
|
},
|
|
24
24
|
"./values": {
|
|
25
25
|
"types": "./lib/utils/values.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./testing/sqlite": {
|
|
28
|
+
"types": "./lib/testing/sqlite.d.ts",
|
|
29
|
+
"default": "./lib/testing/sqlite.js"
|
|
30
|
+
},
|
|
31
|
+
"./testing/sqliteBackend": {
|
|
32
|
+
"types": "./lib/testing/sqliteBackend.d.ts",
|
|
33
|
+
"default": "./lib/testing/sqliteBackend.js"
|
|
34
|
+
},
|
|
35
|
+
"./tanstack": {
|
|
36
|
+
"types": "./lib/tanstack/index.d.ts",
|
|
37
|
+
"default": "./lib/tanstack/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./query": {
|
|
40
|
+
"types": "./lib/query.d.ts",
|
|
41
|
+
"default": "./lib/query.js"
|
|
42
|
+
},
|
|
43
|
+
"./http": {
|
|
44
|
+
"types": "./lib/http.d.ts",
|
|
45
|
+
"default": "./lib/http.js"
|
|
46
|
+
},
|
|
47
|
+
"./local": {
|
|
48
|
+
"types": "./lib/local.d.ts",
|
|
49
|
+
"default": "./lib/local.js"
|
|
50
|
+
},
|
|
51
|
+
"./worker": {
|
|
52
|
+
"types": "./lib/worker.d.ts",
|
|
53
|
+
"default": "./lib/worker.js"
|
|
54
|
+
},
|
|
55
|
+
"./authentication": {
|
|
56
|
+
"types": "./lib/authentication.d.ts",
|
|
57
|
+
"default": "./lib/authentication.js"
|
|
26
58
|
}
|
|
27
59
|
},
|
|
28
60
|
"dependencies": {
|
|
29
61
|
"@bobbyfidz/panic": "^0.1.0",
|
|
62
|
+
"@effect/platform-browser": "^4.0.5",
|
|
63
|
+
"@effect/platform-node": "^4.0.5",
|
|
30
64
|
"@next/env": "^16.1.6",
|
|
31
|
-
"@tanstack/db-sqlite-persistence-core": "0.4.9",
|
|
32
65
|
"change-case": "^5.4.4",
|
|
33
|
-
"
|
|
34
|
-
"effection": "^4.0.2",
|
|
66
|
+
"effect": "^4.0.5",
|
|
35
67
|
"jiti": "^2.6.1",
|
|
36
|
-
"oxfmt": "^0.72.0",
|
|
37
68
|
"temporal-polyfill": "^0.3.0",
|
|
38
|
-
"ts-morph": "^27.0.2",
|
|
39
69
|
"zod": "^4.4.3",
|
|
40
|
-
"@party-stack/
|
|
41
|
-
"@party-stack/
|
|
42
|
-
"@party-stack/
|
|
43
|
-
"@party-stack/
|
|
44
|
-
"@party-stack/
|
|
45
|
-
"@party-stack/
|
|
46
|
-
"@party-stack/
|
|
70
|
+
"@party-stack/connect": "0.2.0",
|
|
71
|
+
"@party-stack/node-runtime": "0.4.0",
|
|
72
|
+
"@party-stack/ontology-backend": "0.2.0",
|
|
73
|
+
"@party-stack/ontology-replica": "0.2.0",
|
|
74
|
+
"@party-stack/ontology-server": "0.11.0",
|
|
75
|
+
"@party-stack/ontology-spec": "0.2.0",
|
|
76
|
+
"@party-stack/ontology-storage": "0.2.0",
|
|
77
|
+
"@party-stack/runtime": "0.5.0",
|
|
78
|
+
"@party-stack/sql-ontology-storage": "0.2.0"
|
|
47
79
|
},
|
|
48
80
|
"devDependencies": {
|
|
49
|
-
"@tanstack/db": "0.
|
|
81
|
+
"@tanstack/db": "1.0.0-rc.1.4",
|
|
82
|
+
"@types/node": "^24.10.1",
|
|
83
|
+
"better-sqlite3": "^12.9.0",
|
|
50
84
|
"tsx": "^4.20.6",
|
|
51
85
|
"typescript": "~7.0.2",
|
|
86
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.2.0",
|
|
52
87
|
"vite-plus": "1.2.0",
|
|
53
|
-
"@party-stack/build-config": "0.
|
|
88
|
+
"@party-stack/build-config": "0.2.0"
|
|
54
89
|
},
|
|
55
90
|
"peerDependencies": {
|
|
56
|
-
"@tanstack/db": "0.
|
|
91
|
+
"@tanstack/db": "1.0.0-rc.1.4"
|
|
57
92
|
},
|
|
58
93
|
"scripts": {
|
|
59
|
-
"bootstrap": "
|
|
94
|
+
"bootstrap": "pnpm --filter @party-stack/ontology-spec bootstrap",
|
|
60
95
|
"generate:examples": "tsx ./src/cli/index.ts generate --ontology ./src/examples/blog.ts --outDir ./src/examples/generated --namespace Blog",
|
|
61
|
-
"generate:meta": "
|
|
96
|
+
"generate:meta": "pnpm --filter @party-stack/ontology-spec generate:meta",
|
|
62
97
|
"ontology": "tsx ./src/cli/index.ts"
|
|
63
98
|
}
|
|
64
99
|
}
|
package/lib/cli/format.d.ts
DELETED
package/lib/cli/format.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","names":[],"sources":["../../src/cli/format.ts"],"mappings":";wBAasB,oBAAoB,kBAAkB,kBAAkB"}
|
package/lib/cli/format.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { format } from "oxfmt";
|
|
2
|
-
//#region src/cli/format.ts
|
|
3
|
-
const options = {
|
|
4
|
-
printWidth: 110,
|
|
5
|
-
tabWidth: 4,
|
|
6
|
-
singleQuote: false,
|
|
7
|
-
semi: true,
|
|
8
|
-
trailingComma: "es5",
|
|
9
|
-
sortImports: false
|
|
10
|
-
};
|
|
11
|
-
async function formatGeneratedFile(filePath, content) {
|
|
12
|
-
const result = await format(filePath, `// Auto-generated file - do not edit manually\n\n${content}`, options);
|
|
13
|
-
if (result.errors.length > 0) throw new Error(`Could not format generated file "${filePath}": ${result.errors.map((error) => error.message).join("; ")}`);
|
|
14
|
-
return result.code;
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
|
-
export { formatGeneratedFile };
|
|
18
|
-
|
|
19
|
-
//# sourceMappingURL=format.js.map
|
package/lib/cli/format.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","names":[],"sources":["../../src/cli/format.ts"],"sourcesContent":["import { format } from \"oxfmt\";\nimport type { FormatConfig } from \"oxfmt\";\n\n// Generator-owned style: consumer configuration must not change generated output.\nconst options: FormatConfig = {\n printWidth: 110,\n tabWidth: 4,\n singleQuote: false,\n semi: true,\n trailingComma: \"es5\",\n sortImports: false,\n};\n\nexport async function formatGeneratedFile(filePath: string, content: string): Promise<string> {\n const result = await format(\n filePath,\n `// Auto-generated file - do not edit manually\\n\\n${content}`,\n options\n );\n if (result.errors.length > 0) {\n throw new Error(\n `Could not format generated file \"${filePath}\": ${result.errors.map((error) => error.message).join(\"; \")}`\n );\n }\n return result.code;\n}\n"],"mappings":";;AAIA,MAAM,UAAwB;CAC1B,YAAY;CACZ,UAAU;CACV,aAAa;CACb,MAAM;CACN,eAAe;CACf,aAAa;AACjB;AAEA,eAAsB,oBAAoB,UAAkB,SAAkC;CAC1F,MAAM,SAAS,MAAM,OACjB,UACA,oDAAoD,WACpD,OACJ;CACA,IAAI,OAAO,OAAO,SAAS,GACvB,MAAM,IAAI,MACN,oCAAoC,SAAS,KAAK,OAAO,OAAO,KAAK,UAAU,MAAM,OAAO,CAAC,CAAC,KAAK,IAAI,GAC3G;CAEJ,OAAO,OAAO;AAClB"}
|
package/lib/cli/generate.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
//#region src/cli/generate.d.ts
|
|
2
|
-
export interface GenerateFilesOpts {
|
|
3
|
-
ontology: string;
|
|
4
|
-
outDir: string;
|
|
5
|
-
namespace?: string;
|
|
6
|
-
jsExtensions?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare function generateFiles(options: GenerateFilesOpts): Promise<void>;
|
|
9
|
-
//#endregion
|
|
10
|
-
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","names":[],"sources":["../../src/cli/generate.ts"],"mappings":";iBAyBiB;EACb;EACA;EACA;EACA;;wBAuDkB,cAAc,SAAS,oBAAoB"}
|
package/lib/cli/generate.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { formatGeneratedFile } from "./format.js";
|
|
3
|
-
import { generateBuilders } from "../generate/builders.js";
|
|
4
|
-
import { generateConstants } from "../generate/constants.js";
|
|
5
|
-
import { generateLive } from "../generate/live.js";
|
|
6
|
-
import { generateTypeDefinitions, generateTypes } from "../generate/types.js";
|
|
7
|
-
import { pascalCase } from "change-case";
|
|
8
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
9
|
-
import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
10
|
-
import { fileURLToPath } from "node:url";
|
|
11
|
-
import { createJiti } from "jiti";
|
|
12
|
-
//#region src/cli/generate.ts
|
|
13
|
-
function toModuleSpecifier(path) {
|
|
14
|
-
const normalized = path.replaceAll("\\", "/");
|
|
15
|
-
if (normalized.startsWith(".")) return normalized;
|
|
16
|
-
return `./${normalized}`;
|
|
17
|
-
}
|
|
18
|
-
function ontologyTypeName(namespace) {
|
|
19
|
-
return namespace.endsWith("Ontology") ? namespace : `${namespace}Ontology`;
|
|
20
|
-
}
|
|
21
|
-
function readPackageName(cwd) {
|
|
22
|
-
try {
|
|
23
|
-
return JSON.parse(readFileSync(resolve(cwd, "package.json"), "utf-8")).name ?? null;
|
|
24
|
-
} catch {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function formatImportSpecifier(path, jsExtensions) {
|
|
29
|
-
const specifier = toModuleSpecifier(path);
|
|
30
|
-
if (jsExtensions) return specifier.replace(/\.[cm]?tsx?$/, ".js");
|
|
31
|
-
return maybeStripJsExtension(specifier, false);
|
|
32
|
-
}
|
|
33
|
-
function maybeStripJsExtension(specifier, jsExtensions) {
|
|
34
|
-
if (jsExtensions || !specifier.startsWith(".")) return specifier;
|
|
35
|
-
return specifier.replace(/\.(?:[cm]?jsx?|[cm]?tsx?)$/, "");
|
|
36
|
-
}
|
|
37
|
-
function resolveValuesImportPath(outDir) {
|
|
38
|
-
const ontologyPackageRoot = fileURLToPath(new URL("../../", import.meta.url));
|
|
39
|
-
if (!resolve(outDir).startsWith(resolve(ontologyPackageRoot))) return "@party-stack/ontology/values";
|
|
40
|
-
const workspaceValuesPath = fileURLToPath(new URL("../../src/utils/values.ts", import.meta.url));
|
|
41
|
-
if (!existsSync(workspaceValuesPath)) return "@party-stack/ontology/values";
|
|
42
|
-
return formatImportSpecifier(relative(outDir, workspaceValuesPath), true);
|
|
43
|
-
}
|
|
44
|
-
async function formatAndWrite(filePath, content) {
|
|
45
|
-
const formatted = await formatGeneratedFile(filePath, content);
|
|
46
|
-
writeFileSync(filePath, formatted, "utf-8");
|
|
47
|
-
}
|
|
48
|
-
function isTypeOnlyOntology(ontology) {
|
|
49
|
-
return ontology.objectTypes.length === 0 && ontology.linkTypes.length === 0 && ontology.actionTypes.length === 0 && ontology.queryFunctionTypes.length === 0;
|
|
50
|
-
}
|
|
51
|
-
async function generateFiles(options) {
|
|
52
|
-
const ontologyPath = resolve(process.cwd(), options.ontology);
|
|
53
|
-
const outDir = resolve(process.cwd(), options.outDir);
|
|
54
|
-
const ontology = (await createJiti(import.meta.url).import(ontologyPath)).default;
|
|
55
|
-
if (!ontology || !Array.isArray(ontology.types) || !Array.isArray(ontology.objectTypes)) throw new Error(`Ontology export from "${options.ontology}" must be an OntologyIR value`);
|
|
56
|
-
mkdirSync(outDir, { recursive: true });
|
|
57
|
-
if (isTypeOnlyOntology(ontology)) {
|
|
58
|
-
const typesFilePath = join(outDir, "types.ts");
|
|
59
|
-
const buildersFilePath = join(outDir, "builders.ts");
|
|
60
|
-
const constantsFilePath = join(outDir, "constants.ts");
|
|
61
|
-
const typesOutput = generateTypeDefinitions(ontology, { valuesImportPath: resolveValuesImportPath(outDir) });
|
|
62
|
-
const buildersOutput = generateBuilders(ontology, {
|
|
63
|
-
exportName: "o",
|
|
64
|
-
promoted: "TypeDef"
|
|
65
|
-
});
|
|
66
|
-
const constantsOutput = generateConstants(ontology);
|
|
67
|
-
await Promise.all([
|
|
68
|
-
formatAndWrite(typesFilePath, typesOutput),
|
|
69
|
-
formatAndWrite(buildersFilePath, buildersOutput),
|
|
70
|
-
formatAndWrite(constantsFilePath, constantsOutput)
|
|
71
|
-
]);
|
|
72
|
-
console.log(`Generated types written to: ${typesFilePath}`);
|
|
73
|
-
console.log(`Generated builders written to: ${buildersFilePath}`);
|
|
74
|
-
console.log(`Generated constants written to: ${constantsFilePath}`);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const ontologyFileName = basename(ontologyPath, extname(ontologyPath));
|
|
78
|
-
const slug = ontologyFileName === "ontology" ? basename(dirname(ontologyPath)) : ontologyFileName;
|
|
79
|
-
const namespace = options.namespace ?? pascalCase(slug);
|
|
80
|
-
const generatedOntologyTypeName = ontologyTypeName(namespace);
|
|
81
|
-
const jsExtensions = options.jsExtensions ?? true;
|
|
82
|
-
const ontologyRuntimeImportPath = maybeStripJsExtension(readPackageName(process.cwd()) === "@party-stack/ontology" ? "../../index.js" : "@party-stack/ontology", jsExtensions);
|
|
83
|
-
const ontologyImportPath = formatImportSpecifier(relative(outDir, ontologyPath), jsExtensions);
|
|
84
|
-
const typesOutput = generateTypes(ontology, { outputTypeName: generatedOntologyTypeName });
|
|
85
|
-
const constantsOutput = generateConstants(ontology);
|
|
86
|
-
const liveOutput = generateLive(ontology, {
|
|
87
|
-
ontologyImportPath,
|
|
88
|
-
ontologyTypesImportPath: maybeStripJsExtension("./types.js", jsExtensions),
|
|
89
|
-
ontologyRuntimeImportPath,
|
|
90
|
-
ontologyTypeName: generatedOntologyTypeName,
|
|
91
|
-
outputFactoryName: `create${namespace}LiveOntology`
|
|
92
|
-
});
|
|
93
|
-
const typesFilePath = join(outDir, "types.ts");
|
|
94
|
-
const liveFilePath = join(outDir, "live.ts");
|
|
95
|
-
const constantsFilePath = join(outDir, "constants.ts");
|
|
96
|
-
await Promise.all([
|
|
97
|
-
formatAndWrite(typesFilePath, typesOutput),
|
|
98
|
-
formatAndWrite(liveFilePath, liveOutput),
|
|
99
|
-
formatAndWrite(constantsFilePath, constantsOutput)
|
|
100
|
-
]);
|
|
101
|
-
console.log(`Generated types written to: ${typesFilePath}`);
|
|
102
|
-
console.log(`Generated live helpers written to: ${liveFilePath}`);
|
|
103
|
-
console.log(`Generated constants written to: ${constantsFilePath}`);
|
|
104
|
-
}
|
|
105
|
-
//#endregion
|
|
106
|
-
export { generateFiles };
|
|
107
|
-
|
|
108
|
-
//# sourceMappingURL=generate.js.map
|
package/lib/cli/generate.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","names":[],"sources":["../../src/cli/generate.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { basename, dirname, extname, join, relative, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { pascalCase } from \"change-case\";\nimport { createJiti } from \"jiti\";\nimport { generateBuilders } from \"../generate/builders.js\";\nimport { generateConstants } from \"../generate/constants.js\";\nimport { generateLive } from \"../generate/live.js\";\nimport { generateTypeDefinitions, generateTypes } from \"../generate/types.js\";\nimport { formatGeneratedFile } from \"./format.js\";\nimport type { OntologyIR } from \"../ir/generated/types.js\";\n\nfunction toModuleSpecifier(path: string): string {\n const normalized = path.replaceAll(\"\\\\\", \"/\");\n if (normalized.startsWith(\".\")) {\n return normalized;\n }\n return `./${normalized}`;\n}\n\nfunction ontologyTypeName(namespace: string): string {\n return namespace.endsWith(\"Ontology\") ? namespace : `${namespace}Ontology`;\n}\n\nexport interface GenerateFilesOpts {\n ontology: string;\n outDir: string;\n namespace?: string;\n jsExtensions?: boolean;\n}\n\nfunction readPackageName(cwd: string): string | null {\n try {\n const packageJson = JSON.parse(readFileSync(resolve(cwd, \"package.json\"), \"utf-8\")) as {\n name?: string;\n };\n return packageJson.name ?? null;\n } catch {\n return null;\n }\n}\n\nfunction formatImportSpecifier(path: string, jsExtensions: boolean): string {\n const specifier = toModuleSpecifier(path);\n if (jsExtensions) {\n return specifier.replace(/\\.[cm]?tsx?$/, \".js\");\n }\n return maybeStripJsExtension(specifier, false);\n}\n\nfunction maybeStripJsExtension(specifier: string, jsExtensions: boolean): string {\n if (jsExtensions || !specifier.startsWith(\".\")) {\n return specifier;\n }\n return specifier.replace(/\\.(?:[cm]?jsx?|[cm]?tsx?)$/, \"\");\n}\n\nfunction resolveValuesImportPath(outDir: string): string {\n const ontologyPackageRoot = fileURLToPath(new URL(\"../../\", import.meta.url));\n if (!resolve(outDir).startsWith(resolve(ontologyPackageRoot))) {\n return \"@party-stack/ontology/values\";\n }\n const workspaceValuesPath = fileURLToPath(new URL(\"../../src/utils/values.ts\", import.meta.url));\n if (!existsSync(workspaceValuesPath)) {\n return \"@party-stack/ontology/values\";\n }\n return formatImportSpecifier(relative(outDir, workspaceValuesPath), true);\n}\n\nasync function formatAndWrite(filePath: string, content: string): Promise<void> {\n const formatted = await formatGeneratedFile(filePath, content);\n writeFileSync(filePath, formatted, \"utf-8\");\n}\n\nfunction isTypeOnlyOntology(ontology: OntologyIR): boolean {\n return (\n ontology.objectTypes.length === 0 &&\n ontology.linkTypes.length === 0 &&\n ontology.actionTypes.length === 0 &&\n ontology.queryFunctionTypes.length === 0\n );\n}\n\nexport async function generateFiles(options: GenerateFilesOpts): Promise<void> {\n const ontologyPath = resolve(process.cwd(), options.ontology);\n const outDir = resolve(process.cwd(), options.outDir);\n const jiti = createJiti(import.meta.url);\n const ontologyModule = await jiti.import(ontologyPath);\n const ontology = (ontologyModule as { default: OntologyIR }).default;\n\n if (!ontology || !Array.isArray(ontology.types) || !Array.isArray(ontology.objectTypes)) {\n throw new Error(`Ontology export from \"${options.ontology}\" must be an OntologyIR value`);\n }\n\n mkdirSync(outDir, { recursive: true });\n\n if (isTypeOnlyOntology(ontology)) {\n const typesFilePath = join(outDir, \"types.ts\");\n const buildersFilePath = join(outDir, \"builders.ts\");\n const constantsFilePath = join(outDir, \"constants.ts\");\n const typesOutput = generateTypeDefinitions(ontology, {\n valuesImportPath: resolveValuesImportPath(outDir),\n });\n const buildersOutput = generateBuilders(ontology, {\n exportName: \"o\",\n promoted: \"TypeDef\",\n });\n const constantsOutput = generateConstants(ontology);\n\n await Promise.all([\n formatAndWrite(typesFilePath, typesOutput),\n formatAndWrite(buildersFilePath, buildersOutput),\n formatAndWrite(constantsFilePath, constantsOutput),\n ]);\n\n console.log(`Generated types written to: ${typesFilePath}`);\n console.log(`Generated builders written to: ${buildersFilePath}`);\n console.log(`Generated constants written to: ${constantsFilePath}`);\n return;\n }\n\n const ontologyFileName = basename(ontologyPath, extname(ontologyPath));\n const slug = ontologyFileName === \"ontology\" ? basename(dirname(ontologyPath)) : ontologyFileName;\n const namespace = options.namespace ?? pascalCase(slug);\n const generatedOntologyTypeName = ontologyTypeName(namespace);\n const jsExtensions = options.jsExtensions ?? true;\n const ontologyRuntimeImportPath = maybeStripJsExtension(\n readPackageName(process.cwd()) === \"@party-stack/ontology\"\n ? \"../../index.js\"\n : \"@party-stack/ontology\",\n jsExtensions\n );\n\n const ontologyImportPath = formatImportSpecifier(relative(outDir, ontologyPath), jsExtensions);\n const typesOutput = generateTypes(ontology, {\n outputTypeName: generatedOntologyTypeName,\n });\n const constantsOutput = generateConstants(ontology);\n const liveOutput = generateLive(ontology, {\n ontologyImportPath,\n ontologyTypesImportPath: maybeStripJsExtension(\"./types.js\", jsExtensions),\n ontologyRuntimeImportPath,\n ontologyTypeName: generatedOntologyTypeName,\n outputFactoryName: `create${namespace}LiveOntology`,\n });\n\n const typesFilePath = join(outDir, \"types.ts\");\n const liveFilePath = join(outDir, \"live.ts\");\n const constantsFilePath = join(outDir, \"constants.ts\");\n\n await Promise.all([\n formatAndWrite(typesFilePath, typesOutput),\n formatAndWrite(liveFilePath, liveOutput),\n formatAndWrite(constantsFilePath, constantsOutput),\n ]);\n\n console.log(`Generated types written to: ${typesFilePath}`);\n console.log(`Generated live helpers written to: ${liveFilePath}`);\n console.log(`Generated constants written to: ${constantsFilePath}`);\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAS,kBAAkB,MAAsB;CAC7C,MAAM,aAAa,KAAK,WAAW,MAAM,GAAG;CAC5C,IAAI,WAAW,WAAW,GAAG,GACzB,OAAO;CAEX,OAAO,KAAK;AAChB;AAEA,SAAS,iBAAiB,WAA2B;CACjD,OAAO,UAAU,SAAS,UAAU,IAAI,YAAY,GAAG,UAAU;AACrE;AASA,SAAS,gBAAgB,KAA4B;CACjD,IAAI;EAIA,OAHoB,KAAK,MAAM,aAAa,QAAQ,KAAK,cAAc,GAAG,OAAO,CAGhE,CAAC,CAAC,QAAQ;CAC/B,QAAQ;EACJ,OAAO;CACX;AACJ;AAEA,SAAS,sBAAsB,MAAc,cAA+B;CACxE,MAAM,YAAY,kBAAkB,IAAI;CACxC,IAAI,cACA,OAAO,UAAU,QAAQ,gBAAgB,KAAK;CAElD,OAAO,sBAAsB,WAAW,KAAK;AACjD;AAEA,SAAS,sBAAsB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AAe,WAAW;EACzC,eAAe,cAAc,UAAU;EACvC,eAAe,mBAAmB,eAAe;CACrD,CAAC;CAED,QAAQ,IAAI,+BAA+B,eAAe;CAC1D,QAAQ,IAAI,sCAAsC,cAAc;CAChE,QAAQ,IAAI,mCAAmC,mBAAmB;AACtE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blog.d.ts","names":[],"sources":["../../src/examples/blog.ts"],"mappings":";;;;;;;;;;;;cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAwLgB;MACA;MACA;;;MAGA;MACA;MACA;;;;;;;MAuBA;MACA;MACA;;;MAGA;MACA;MACA"}
|
package/lib/examples/blog.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blog.js","names":[],"sources":["../../src/examples/blog.ts"],"sourcesContent":["/**\n * Example: Blog ontology with Authors, Posts, and Comments.\n *\n * Demonstrates:\n * - Object types with primary keys and typed properties\n * - Value types (reusable structured types)\n * - Link types with cardinality\n * - Attachment properties (e.g. author avatar)\n * - String enum constraints (e.g. post status)\n * - Optional properties and timestamps\n */\n\nimport { o } from \"../ir/generated/builders.js\";\nimport type { OntologyIR } from \"../ir/generated/types.js\";\n\nexport default {\n types: [\n {\n name: \"Address\",\n description: \"A mailing address.\",\n type: o.struct({\n fields: [\n { name: \"line1\", displayName: \"Line 1\", type: o.string({}) },\n {\n name: \"line2\",\n displayName: \"Line 2\",\n type: o.optional({ type: o.string({}) }),\n },\n { name: \"city\", displayName: \"City\", type: o.string({}) },\n { name: \"state\", displayName: \"State\", type: o.string({}) },\n { name: \"zip\", displayName: \"ZIP\", type: o.string({}) },\n ],\n }),\n },\n ],\n\n objectTypes: [\n {\n name: \"Author\",\n displayName: \"Author\",\n pluralDisplayName: \"Authors\",\n description: \"A blog author.\",\n primaryKey: \"authorId\",\n properties: [\n {\n name: \"authorId\",\n displayName: \"Author ID\",\n type: o.string({}),\n },\n {\n name: \"name\",\n displayName: \"Name\",\n type: o.string({}),\n },\n {\n name: \"email\",\n displayName: \"Email\",\n type: o.string({}),\n },\n {\n name: \"bio\",\n displayName: \"Bio\",\n type: o.optional({ type: o.string({}) }),\n },\n {\n name: \"avatar\",\n displayName: \"Avatar\",\n description: \"The author's profile picture.\",\n type: o.optional({ type: o.attachment({}) }),\n },\n {\n name: \"address\",\n displayName: \"Address\",\n type: o.optional({ type: o.ref({ name: \"Address\" }) }),\n },\n {\n name: \"createdAt\",\n displayName: \"Created At\",\n type: o.timestamp({}),\n },\n ],\n },\n {\n name: \"Post\",\n displayName: \"Blog Post\",\n pluralDisplayName: \"Posts\",\n description: \"A blog post.\",\n primaryKey: \"postId\",\n properties: [\n {\n name: \"postId\",\n displayName: \"Post ID\",\n type: o.string({}),\n },\n {\n name: \"title\",\n displayName: \"Title\",\n type: o.string({}),\n },\n {\n name: \"body\",\n displayName: \"Body\",\n type: o.string({}),\n },\n {\n name: \"authorId\",\n displayName: \"Author ID\",\n type: o.string({}),\n },\n {\n name: \"status\",\n displayName: \"Status\",\n type: o.string({\n constraint: o.StringConstraint.enum({\n options: [\n { value: \"draft\", label: \"Draft\" },\n { value: \"published\", label: \"Published\" },\n { value: \"archived\", label: \"Archived\" },\n ],\n }),\n }),\n },\n {\n name: \"coverImage\",\n displayName: \"Cover Image\",\n type: o.optional({ type: o.attachment({}) }),\n },\n {\n name: \"tags\",\n displayName: \"Tags\",\n type: o.list({ elementType: o.string({}) }),\n },\n {\n name: \"createdAt\",\n displayName: \"Created At\",\n type: o.timestamp({}),\n },\n {\n name: \"publishedAt\",\n displayName: \"Published At\",\n type: o.optional({ type: o.timestamp({}) }),\n },\n ],\n },\n {\n name: \"Comment\",\n displayName: \"Comment\",\n pluralDisplayName: \"Comments\",\n description: \"A comment on a blog post.\",\n primaryKey: \"commentId\",\n properties: [\n {\n name: \"commentId\",\n displayName: \"Comment ID\",\n type: o.string({}),\n },\n {\n name: \"body\",\n displayName: \"Body\",\n type: o.string({}),\n },\n {\n name: \"postId\",\n displayName: \"Post ID\",\n type: o.string({}),\n },\n {\n name: \"authorId\",\n displayName: \"Author ID\",\n type: o.string({}),\n },\n {\n name: \"createdAt\",\n displayName: \"Created At\",\n type: o.timestamp({}),\n },\n ],\n },\n ],\n\n linkTypes: [\n {\n id: \"Post:author\",\n source: {\n objectType: \"Post\",\n name: \"posts\",\n displayName: \"Posts\",\n },\n target: {\n objectType: \"Author\",\n name: \"author\",\n displayName: \"Author\",\n },\n foreignKey: \"authorId\",\n cardinality: \"many\",\n },\n {\n id: \"Comment:post\",\n source: {\n objectType: \"Comment\",\n name: \"comments\",\n displayName: \"Comments\",\n },\n target: {\n objectType: \"Post\",\n name: \"post\",\n displayName: \"Post\",\n },\n foreignKey: \"postId\",\n cardinality: \"many\",\n },\n {\n id: \"Comment:author\",\n source: {\n objectType: \"Comment\",\n name: \"comment\",\n displayName: \"Comment\",\n },\n target: {\n objectType: \"Author\",\n name: \"author\",\n displayName: \"Author\",\n },\n foreignKey: \"authorId\",\n cardinality: \"one\",\n },\n ],\n actionTypes: [\n {\n name: \"createPost\",\n displayName: \"Create Post\",\n description: \"Create a new blog post.\",\n parameters: [\n {\n name: \"postId\",\n displayName: \"Post ID\",\n type: o.string({}),\n defaultValue: o.Expression.uuid({}),\n },\n {\n name: \"author\",\n displayName: \"Author\",\n type: o.objectReference({ objectType: \"Author\" }),\n },\n {\n name: \"title\",\n displayName: \"Title\",\n type: o.string({}),\n },\n {\n name: \"body\",\n displayName: \"Body\",\n type: o.string({}),\n },\n {\n name: \"status\",\n displayName: \"Status\",\n type: o.string({\n constraint: o.StringConstraint.enum({\n options: [\n { value: \"draft\", label: \"Draft\" },\n { value: \"published\", label: \"Published\" },\n { value: \"archived\", label: \"Archived\" },\n ],\n }),\n }),\n },\n {\n name: \"tags\",\n displayName: \"Tags\",\n type: o.list({ elementType: o.string({}) }),\n },\n {\n name: \"createdAt\",\n displayName: \"Created At\",\n type: o.timestamp({}),\n defaultValue: o.Expression.now({}),\n },\n ],\n logic: [\n o.ActionLogicStep.createObject({\n objectType: \"Post\",\n values: [\n {\n property: [\"postId\"],\n value: o.Expression.inputReference({ name: \"postId\" }),\n },\n {\n property: [\"title\"],\n value: o.Expression.inputReference({ name: \"title\" }),\n },\n {\n property: [\"body\"],\n value: o.Expression.inputReference({ name: \"body\" }),\n },\n {\n property: [\"authorId\"],\n value: o.Expression.getAt({\n source: o.Expression.objectLookup({\n reference: o.Expression.inputReference({\n name: \"author\",\n }),\n }),\n path: [\"authorId\"],\n }),\n },\n {\n property: [\"status\"],\n value: o.Expression.inputReference({ name: \"status\" }),\n },\n {\n property: [\"tags\"],\n value: o.Expression.inputReference({ name: \"tags\" }),\n },\n {\n property: [\"createdAt\"],\n value: o.Expression.inputReference({ name: \"createdAt\" }),\n },\n ],\n }),\n ],\n },\n ],\n queryFunctionTypes: [\n {\n name: \"searchPosts\",\n displayName: \"Search Posts\",\n description: \"Search blog posts by query text.\",\n parameters: [\n {\n name: \"query\",\n displayName: \"Query\",\n type: o.string({}),\n },\n {\n name: \"limit\",\n displayName: \"Limit\",\n type: o.optional({ type: o.integer({}) }),\n },\n ],\n returnType: o.list({ elementType: o.objectReference({ objectType: \"Post\" }) }),\n },\n ],\n} satisfies OntologyIR;\n"],"mappings":";;;;;;;;;;;;;AAeA,IAAA,eAAe;CACX,OAAO,CACH;EACI,MAAM;EACN,aAAa;EACb,MAAM,EAAE,OAAO,EACX,QAAQ;GACJ;IAAE,MAAM;IAAS,aAAa;IAAU,MAAM,EAAE,OAAO,CAAC,CAAC;GAAE;GAC3D;IACI,MAAM;IACN,aAAa;IACb,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC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import "../ir/index.js";
|
|
3
|
-
//#region src/generate/builders.d.ts
|
|
4
|
-
export interface GenerateBuildersOpts {
|
|
5
|
-
/** The name of the main export (e.g., "o" for `o.string()`). */
|
|
6
|
-
exportName: string;
|
|
7
|
-
/** If set, promotes this union type's variants to the top level of the export. */
|
|
8
|
-
promoted?: string;
|
|
9
|
-
}
|
|
10
|
-
export declare function generateBuilders(schema: Pick<OntologyIR, "types">, opts: GenerateBuildersOpts): string;
|
|
11
|
-
//#endregion
|
|
12
|
-
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"builders.d.ts","names":[],"sources":["../../src/generate/builders.ts"],"mappings":";;;iBAIiB;;EAEb;;EAEA;;wBAaY,iBAAiB,QAAQ,KAAK,sBAAsB,MAAM"}
|
package/lib/generate/builders.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { buildJsDocs } from "./utils/buildJsDocs.js";
|
|
2
|
-
import { Project, VariableDeclarationKind } from "ts-morph";
|
|
3
|
-
//#region src/generate/builders.ts
|
|
4
|
-
function unionTypeToBuilders(name, unionType) {
|
|
5
|
-
return unionType.variants.map((variant) => ({
|
|
6
|
-
name: variant.name,
|
|
7
|
-
builder: `<const Value extends Extract<t.${name}, { kind: "${variant.name}" }>["value"]>(value: Value) => ({ kind: "${variant.name}" as const, value })`
|
|
8
|
-
}));
|
|
9
|
-
}
|
|
10
|
-
function generateBuilders(schema, opts) {
|
|
11
|
-
const sourceFile = new Project({ useInMemoryFileSystem: true }).createSourceFile("builders.ts", "");
|
|
12
|
-
const unionTypes = schema.types.filter((type) => type.type.kind === "union");
|
|
13
|
-
if (unionTypes.length === 0) return "";
|
|
14
|
-
sourceFile.addImportDeclaration({
|
|
15
|
-
moduleSpecifier: "./types.js",
|
|
16
|
-
namespaceImport: "t"
|
|
17
|
-
});
|
|
18
|
-
const promotedType = unionTypes.find((type) => type.name === opts.promoted);
|
|
19
|
-
const promotedBuilders = promotedType ? unionTypeToBuilders(opts.promoted, promotedType.type.value) : [];
|
|
20
|
-
const nestedTypes = unionTypes.filter((type) => type.name !== opts.promoted);
|
|
21
|
-
for (const builder of promotedBuilders) sourceFile.addVariableStatement({
|
|
22
|
-
isExported: true,
|
|
23
|
-
declarationKind: VariableDeclarationKind.Const,
|
|
24
|
-
declarations: [{
|
|
25
|
-
name: builder.name,
|
|
26
|
-
initializer: builder.builder
|
|
27
|
-
}],
|
|
28
|
-
docs: buildJsDocs({ deprecated: promotedType?.deprecated })
|
|
29
|
-
});
|
|
30
|
-
for (const nestedType of nestedTypes) {
|
|
31
|
-
const builders = unionTypeToBuilders(nestedType.name, nestedType.type.value);
|
|
32
|
-
sourceFile.addVariableStatement({
|
|
33
|
-
isExported: true,
|
|
34
|
-
declarationKind: VariableDeclarationKind.Const,
|
|
35
|
-
declarations: [{
|
|
36
|
-
name: nestedType.name,
|
|
37
|
-
initializer: `{ ${builders.map((builder) => `${builder.name}: ${builder.builder}`).join(", ")} }`
|
|
38
|
-
}],
|
|
39
|
-
docs: buildJsDocs({ deprecated: nestedType.deprecated })
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
const exportNames = [...promotedBuilders.map((builder) => builder.name), ...nestedTypes.map((type) => type.name)];
|
|
43
|
-
sourceFile.addVariableStatement({
|
|
44
|
-
isExported: true,
|
|
45
|
-
declarationKind: VariableDeclarationKind.Const,
|
|
46
|
-
declarations: [{
|
|
47
|
-
name: opts.exportName,
|
|
48
|
-
initializer: `{ ${exportNames.join(", ")} }`
|
|
49
|
-
}]
|
|
50
|
-
});
|
|
51
|
-
const statements = sourceFile.getVariableStatements();
|
|
52
|
-
for (const statement of statements.slice(0, -1)) statement.appendWhitespace("\n");
|
|
53
|
-
return sourceFile.getFullText().trim();
|
|
54
|
-
}
|
|
55
|
-
//#endregion
|
|
56
|
-
export { generateBuilders };
|
|
57
|
-
|
|
58
|
-
//# sourceMappingURL=builders.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"builders.js","names":[],"sources":["../../src/generate/builders.ts"],"sourcesContent":["import { Project, VariableDeclarationKind } from \"ts-morph\";\nimport { buildJsDocs } from \"./utils/buildJsDocs.js\";\nimport type { NamedTypeDef, OntologyIR, UnionTypeDef } from \"../ir/index.js\";\n\nexport interface GenerateBuildersOpts {\n /** The name of the main export (e.g., \"o\" for `o.string()`). */\n exportName: string;\n /** If set, promotes this union type's variants to the top level of the export. */\n promoted?: string;\n}\n\nfunction unionTypeToBuilders(\n name: string,\n unionType: UnionTypeDef\n): Array<{ name: string; builder: string }> {\n return unionType.variants.map((variant) => ({\n name: variant.name,\n builder: `<const Value extends Extract<t.${name}, { kind: \"${variant.name}\" }>[\"value\"]>(value: Value) => ({ kind: \"${variant.name}\" as const, value })`,\n }));\n}\n\nexport function generateBuilders(schema: Pick<OntologyIR, \"types\">, opts: GenerateBuildersOpts): string {\n const project = new Project({ useInMemoryFileSystem: true });\n const sourceFile = project.createSourceFile(\"builders.ts\", \"\");\n\n const unionTypes = schema.types.filter((type) => type.type.kind === \"union\") as Array<\n NamedTypeDef & {\n type: { kind: \"union\"; value: UnionTypeDef };\n }\n >;\n\n if (unionTypes.length === 0) {\n return \"\";\n }\n\n sourceFile.addImportDeclaration({\n moduleSpecifier: \"./types.js\",\n namespaceImport: \"t\",\n });\n\n const promotedType = unionTypes.find((type) => type.name === opts.promoted);\n const promotedBuilders = promotedType ? unionTypeToBuilders(opts.promoted!, promotedType.type.value) : [];\n\n const nestedTypes = unionTypes.filter((type) => type.name !== opts.promoted);\n\n for (const builder of promotedBuilders) {\n sourceFile.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [{ name: builder.name, initializer: builder.builder }],\n docs: buildJsDocs({ deprecated: promotedType?.deprecated }),\n });\n }\n\n for (const nestedType of nestedTypes) {\n const builders = unionTypeToBuilders(nestedType.name, nestedType.type.value);\n sourceFile.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: nestedType.name,\n initializer: `{ ${builders.map((builder) => `${builder.name}: ${builder.builder}`).join(\", \")} }`,\n },\n ],\n docs: buildJsDocs({ deprecated: nestedType.deprecated }),\n });\n }\n\n const exportNames = [\n ...promotedBuilders.map((builder) => builder.name),\n ...nestedTypes.map((type) => type.name),\n ];\n sourceFile.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [{ name: opts.exportName, initializer: `{ ${exportNames.join(\", \")} }` }],\n });\n\n const statements = sourceFile.getVariableStatements();\n for (const statement of statements.slice(0, -1)) {\n statement.appendWhitespace(\"\\n\");\n }\n\n return sourceFile.getFullText().trim();\n}\n"],"mappings":";;;AAWA,SAAS,oBACL,MACA,WACwC;CACxC,OAAO,UAAU,SAAS,KAAK,aAAa;EACxC,MAAM,QAAQ;EACd,SAAS,kCAAkC,KAAK,aAAa,QAAQ,KAAK,4CAA4C,QAAQ,KAAK;CACvI,EAAE;AACN;AAEA,SAAgB,iBAAiB,QAAmC,MAAoC;CAEpG,MAAM,aAAa,IADC,QAAQ,EAAE,uBAAuB,KAAK,CACjC,CAAC,CAAC,iBAAiB,eAAe,EAAE;CAE7D,MAAM,aAAa,OAAO,MAAM,QAAQ,SAAS,KAAK,KAAK,SAAS,OAAO;CAM3E,IAAI,WAAW,WAAW,GACtB,OAAO;CAGX,WAAW,qBAAqB;EAC5B,iBAAiB;EACjB,iBAAiB;CACrB,CAAC;CAED,MAAM,eAAe,WAAW,MAAM,SAAS,KAAK,SAAS,KAAK,QAAQ;CAC1E,MAAM,mBAAmB,eAAe,oBAAoB,KAAK,UAAW,aAAa,KAAK,KAAK,IAAI,CAAC;CAExG,MAAM,cAAc,WAAW,QAAQ,SAAS,KAAK,SAAS,KAAK,QAAQ;CAE3E,KAAK,MAAM,WAAW,kBAClB,WAAW,qBAAqB;EAC5B,YAAY;EACZ,iBAAiB,wBAAwB;EACzC,cAAc,CAAC;GAAE,MAAM,QAAQ;GAAM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