@palantir/pack.state.foundry 0.0.1-beta.1

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.
@@ -0,0 +1,4 @@
1
+
2
+ > @palantir/pack.state.foundry@0.0.1-beta.1 lint /home/runner/work/pack/pack/packages/state/foundry
3
+ > eslint ./src ; dprint check --config $(find-up dprint.json) --allow-no-files
4
+
@@ -0,0 +1,5 @@
1
+
2
+ > @palantir/pack.state.foundry@0.0.1-beta.1 transpileBrowser /home/runner/work/pack/pack/packages/state/foundry
3
+ > monorepo-transpile -f esm -m bundle -t browser
4
+
5
+ 👍
@@ -0,0 +1,5 @@
1
+
2
+ > @palantir/pack.state.foundry@0.0.1-beta.1 transpileCjs /home/runner/work/pack/pack/packages/state/foundry
3
+ > monorepo-transpile -f cjs -m bundle -t node
4
+
5
+ 👍
@@ -0,0 +1,5 @@
1
+
2
+ > @palantir/pack.state.foundry@0.0.1-beta.1 transpileEsm /home/runner/work/pack/pack/packages/state/foundry
3
+ > monorepo-transpile -f esm -m bundle -t node
4
+
5
+ 👍
@@ -0,0 +1,5 @@
1
+
2
+ > @palantir/pack.state.foundry@0.0.1-beta.1 transpileTypes /home/runner/work/pack/pack/packages/state/foundry
3
+ > monorepo-transpile -f esm -m types -t node
4
+
5
+ 👍
@@ -0,0 +1,4 @@
1
+
2
+ > @palantir/pack.state.foundry@0.0.1-beta.1 typecheck /home/runner/work/pack/pack/packages/state/foundry
3
+ > tsc --noEmit --emitDeclarationOnly false
4
+
package/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2025 Palantir Technologies, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @palantir/pack.state.foundry
2
+
3
+ State service implementation that connects to foundry platform apis.
@@ -0,0 +1,126 @@
1
+ import { Documents } from '@osdk/foundry.pack';
2
+ import { createDocumentServiceConfig, BaseYjsDocumentService, DocumentLoadStatus } from '@palantir/pack.state.core';
3
+ import { createFoundryEventService } from '@palantir/pack.state.foundry-event';
4
+
5
+ // src/FoundryDocumentService.ts
6
+ var DEFAULT_USE_PREVIEW_API = true;
7
+ function createFoundryDocumentServiceConfig(config = {}) {
8
+ return createDocumentServiceConfig((app, config2) => internalCreateFoundryDocumentService(app, config2), config);
9
+ }
10
+ function internalCreateFoundryDocumentService(app, config, eventService) {
11
+ return new FoundryDocumentService(app, config, createFoundryEventService(app));
12
+ }
13
+ var FoundryDocumentService = class extends BaseYjsDocumentService {
14
+ constructor(app, config, eventService) {
15
+ super(app, app.config.logger.child({}, {
16
+ level: "debug",
17
+ msgPrefix: "FoundryDocumentService"
18
+ }));
19
+ this.config = config;
20
+ this.eventService = eventService;
21
+ }
22
+ createInternalDoc(ref, metadata, initialYDoc) {
23
+ return {
24
+ ...this.createBaseInternalDoc(ref, metadata, initialYDoc),
25
+ syncSession: void 0
26
+ };
27
+ }
28
+ get hasMetadataSubscriptions() {
29
+ return Array.from(this.documents.values()).some((doc) => this.hasSubscriptions(doc) && doc.metadataSubscribers.size > 0);
30
+ }
31
+ get hasStateSubscriptions() {
32
+ return Array.from(this.documents.values()).some((doc) => this.hasSubscriptions(doc) && doc.docStateSubscribers.size > 0);
33
+ }
34
+ createDocument = async (metadata, schema) => {
35
+ const {
36
+ documentTypeName,
37
+ name,
38
+ ontologyRid,
39
+ security
40
+ } = metadata;
41
+ const request = {
42
+ documentTypeName,
43
+ name,
44
+ ontologyRid,
45
+ security: getWireSecurity(security)
46
+ };
47
+ const createResponse = await Documents.create(this.app.config.osdkClient, request, {
48
+ preview: this.config.usePreviewApi ?? DEFAULT_USE_PREVIEW_API
49
+ });
50
+ const documentId = createResponse.id;
51
+ const docRef = this.createDocRef(documentId, schema);
52
+ return docRef;
53
+ };
54
+ onMetadataSubscriptionOpened(internalDoc, docRef) {
55
+ if (internalDoc.metadataStatus.load !== DocumentLoadStatus.UNLOADED) {
56
+ throw new Error(`Cannot subscribe to document metadata when status is ${internalDoc.metadataStatus.load}`);
57
+ }
58
+ this.updateMetadataStatus(internalDoc, docRef, {
59
+ load: DocumentLoadStatus.LOADING
60
+ });
61
+ Documents.get(this.app.config.osdkClient, docRef.id, {
62
+ preview: this.config.usePreviewApi ?? DEFAULT_USE_PREVIEW_API
63
+ }).then((document) => {
64
+ const metadata = {
65
+ documentTypeName: document.documentTypeName,
66
+ name: document.name,
67
+ ontologyRid: "unknown",
68
+ security: {
69
+ discretionary: {
70
+ owners: []
71
+ },
72
+ mandatory: {}
73
+ }
74
+ };
75
+ internalDoc.metadata = metadata;
76
+ this.notifyMetadataSubscribers(internalDoc, docRef, metadata);
77
+ this.updateMetadataStatus(internalDoc, docRef, {
78
+ load: DocumentLoadStatus.LOADED
79
+ });
80
+ }).catch((e) => {
81
+ const error = new Error("Failed to load document metadata", {
82
+ cause: e
83
+ });
84
+ this.updateMetadataStatus(internalDoc, docRef, {
85
+ error,
86
+ load: DocumentLoadStatus.ERROR
87
+ });
88
+ });
89
+ }
90
+ onDataSubscriptionOpened(internalDoc, docRef) {
91
+ if (internalDoc.syncSession != null) {
92
+ throw new Error("Document data subscription already opened");
93
+ }
94
+ internalDoc.syncSession = this.eventService.startDocumentSync(docRef.id, internalDoc.yDoc, (status) => {
95
+ this.updateDataStatus(internalDoc, docRef, status);
96
+ });
97
+ }
98
+ onMetadataSubscriptionClosed(_internalDoc, _docRef) {
99
+ }
100
+ onDataSubscriptionClosed(internalDoc, _docRef) {
101
+ if (internalDoc.syncSession) {
102
+ this.eventService.stopDocumentSync(internalDoc.syncSession);
103
+ internalDoc.syncSession = void 0;
104
+ }
105
+ }
106
+ };
107
+ function mutableArray(array) {
108
+ return array == null ? [] : array;
109
+ }
110
+ function getWireSecurity(security) {
111
+ return {
112
+ discretionary: {
113
+ editors: [...security.discretionary.editors ?? []],
114
+ owners: [...security.discretionary.owners],
115
+ viewers: [...security.discretionary.viewers ?? []]
116
+ },
117
+ mandatory: {
118
+ classification: mutableArray(security.mandatory.classification),
119
+ markings: mutableArray(security.mandatory.markings)
120
+ }
121
+ };
122
+ }
123
+
124
+ export { createFoundryDocumentServiceConfig };
125
+ //# sourceMappingURL=index.js.map
126
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/FoundryDocumentService.ts"],"names":["config"],"mappings":";;;;;AAmBA,IAAM,uBAAA,GAA0B,IAAA;AACzB,SAAS,kCAAA,CAAmC,MAAA,GAAS,EAAC,EAAG;AAC9D,EAAA,OAAO,2BAAA,CAA4B,CAAC,GAAA,EAAKA,OAAAA,KAAW,qCAAqC,GAAA,EAAKA,OAAM,GAAG,MAAM,CAAA;AAC/G;AACO,SAAS,oCAAA,CAAqC,GAAA,EAAK,MAAA,EAAQ,YAAA,EAAc;AAC9E,EAAA,OAAO,IAAI,sBAAA,CAAuB,GAAA,EAAK,QAAwB,yBAAA,CAA0B,GAAG,CAAC,CAAA;AAC/F;AACO,IAAM,sBAAA,GAAN,cAAqC,sBAAA,CAAuB;AAAA,EACjE,WAAA,CAAY,GAAA,EAAK,MAAA,EAAQ,YAAA,EAAc;AACrC,IAAA,KAAA,CAAM,KAAK,GAAA,CAAI,MAAA,CAAO,MAAA,CAAO,KAAA,CAAM,EAAC,EAAG;AAAA,MACrC,KAAA,EAAO,OAAA;AAAA,MACP,SAAA,EAAW;AAAA,KACZ,CAAC,CAAA;AACF,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,YAAA,GAAe,YAAA;AAAA,EACtB;AAAA,EACA,iBAAA,CAAkB,GAAA,EAAK,QAA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AA,KACrD;AAAA,IACA,SAAA,EAAW;AAAA,MACT,cAAA,EAAgB,YAAA,CAAa,QAAA,CAAS,SAAA,CAAU,cAAc,CAAA;AAAA,MAC9D,QAAA,EAAU,YAAA,CAAa,QAAA,CAAS,SAAA,CAAU,QAAQ;AAAA;AACpD,GACF;AACF","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Documents } from \"@osdk/foundry.pack\";\nimport { BaseYjsDocumentService, createDocumentServiceConfig, DocumentLoadStatus } from \"@palantir/pack.state.core\";\nimport { createFoundryEventService } from \"@palantir/pack.state.foundry-event\";\nconst DEFAULT_USE_PREVIEW_API = true;\nexport function createFoundryDocumentServiceConfig(config = {}) {\n return createDocumentServiceConfig((app, config) => internalCreateFoundryDocumentService(app, config), config);\n}\nexport function internalCreateFoundryDocumentService(app, config, eventService) {\n return new FoundryDocumentService(app, config, eventService ?? createFoundryEventService(app));\n}\nexport class FoundryDocumentService extends BaseYjsDocumentService {\n constructor(app, config, eventService) {\n super(app, app.config.logger.child({}, {\n level: \"debug\",\n msgPrefix: \"FoundryDocumentService\"\n }));\n this.config = config;\n this.eventService = eventService;\n }\n createInternalDoc(ref, metadata, initialYDoc) {\n return {\n ...this.createBaseInternalDoc(ref, metadata, initialYDoc),\n syncSession: undefined\n };\n }\n get hasMetadataSubscriptions() {\n return Array.from(this.documents.values()).some(doc => this.hasSubscriptions(doc) && doc.metadataSubscribers.size > 0);\n }\n get hasStateSubscriptions() {\n return Array.from(this.documents.values()).some(doc => this.hasSubscriptions(doc) && doc.docStateSubscribers.size > 0);\n }\n createDocument = async (metadata, schema) => {\n const {\n documentTypeName,\n name,\n ontologyRid,\n security\n } = metadata;\n const request = {\n documentTypeName: documentTypeName,\n name: name,\n ontologyRid: ontologyRid,\n security: getWireSecurity(security)\n };\n const createResponse = await Documents.create(this.app.config.osdkClient, request, {\n preview: this.config.usePreviewApi ?? DEFAULT_USE_PREVIEW_API\n });\n const documentId = createResponse.id;\n const docRef = this.createDocRef(documentId, schema);\n return docRef;\n };\n onMetadataSubscriptionOpened(internalDoc, docRef) {\n if (internalDoc.metadataStatus.load !== DocumentLoadStatus.UNLOADED) {\n throw new Error(`Cannot subscribe to document metadata when status is ${internalDoc.metadataStatus.load}`);\n }\n this.updateMetadataStatus(internalDoc, docRef, {\n load: DocumentLoadStatus.LOADING\n });\n Documents.get(this.app.config.osdkClient, docRef.id, {\n preview: this.config.usePreviewApi ?? DEFAULT_USE_PREVIEW_API\n }).then(document => {\n const metadata = {\n documentTypeName: document.documentTypeName,\n name: document.name,\n ontologyRid: \"unknown\",\n security: {\n discretionary: {\n owners: []\n },\n mandatory: {}\n }\n };\n internalDoc.metadata = metadata;\n this.notifyMetadataSubscribers(internalDoc, docRef, metadata);\n this.updateMetadataStatus(internalDoc, docRef, {\n load: DocumentLoadStatus.LOADED\n });\n }).catch(e => {\n const error = new Error(\"Failed to load document metadata\", {\n cause: e\n });\n this.updateMetadataStatus(internalDoc, docRef, {\n error,\n load: DocumentLoadStatus.ERROR\n });\n });\n }\n onDataSubscriptionOpened(internalDoc, docRef) {\n if (internalDoc.syncSession != null) {\n throw new Error(\"Document data subscription already opened\");\n }\n internalDoc.syncSession = this.eventService.startDocumentSync(docRef.id, internalDoc.yDoc, status => {\n this.updateDataStatus(internalDoc, docRef, status);\n });\n }\n onMetadataSubscriptionClosed(_internalDoc, _docRef) {}\n onDataSubscriptionClosed(internalDoc, _docRef) {\n if (internalDoc.syncSession) {\n this.eventService.stopDocumentSync(internalDoc.syncSession);\n internalDoc.syncSession = undefined;\n }\n }\n}\nfunction mutableArray(array) {\n return array == null ? [] : array;\n}\nfunction getWireSecurity(security) {\n return {\n discretionary: {\n editors: [...(security.discretionary.editors ?? [])],\n owners: [...security.discretionary.owners],\n viewers: [...(security.discretionary.viewers ?? [])]\n },\n mandatory: {\n classification: mutableArray(security.mandatory.classification),\n markings: mutableArray(security.mandatory.markings)\n }\n };\n}"]}
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+
3
+ var foundry_pack = require('@osdk/foundry.pack');
4
+ var pack_state_core = require('@palantir/pack.state.core');
5
+ var pack_state_foundryEvent = require('@palantir/pack.state.foundry-event');
6
+
7
+ // src/FoundryDocumentService.ts
8
+ var DEFAULT_USE_PREVIEW_API = true;
9
+ function createFoundryDocumentServiceConfig(config = {}) {
10
+ return pack_state_core.createDocumentServiceConfig((app, config2) => internalCreateFoundryDocumentService(app, config2), config);
11
+ }
12
+ function internalCreateFoundryDocumentService(app, config, eventService) {
13
+ return new FoundryDocumentService(app, config, pack_state_foundryEvent.createFoundryEventService(app));
14
+ }
15
+ var FoundryDocumentService = class extends pack_state_core.BaseYjsDocumentService {
16
+ constructor(app, config, eventService) {
17
+ super(app, app.config.logger.child({}, {
18
+ level: "debug",
19
+ msgPrefix: "FoundryDocumentService"
20
+ }));
21
+ this.config = config;
22
+ this.eventService = eventService;
23
+ }
24
+ createInternalDoc(ref, metadata, initialYDoc) {
25
+ return {
26
+ ...this.createBaseInternalDoc(ref, metadata, initialYDoc),
27
+ syncSession: void 0
28
+ };
29
+ }
30
+ get hasMetadataSubscriptions() {
31
+ return Array.from(this.documents.values()).some((doc) => this.hasSubscriptions(doc) && doc.metadataSubscribers.size > 0);
32
+ }
33
+ get hasStateSubscriptions() {
34
+ return Array.from(this.documents.values()).some((doc) => this.hasSubscriptions(doc) && doc.docStateSubscribers.size > 0);
35
+ }
36
+ createDocument = async (metadata, schema) => {
37
+ const {
38
+ documentTypeName,
39
+ name,
40
+ ontologyRid,
41
+ security
42
+ } = metadata;
43
+ const request = {
44
+ documentTypeName,
45
+ name,
46
+ ontologyRid,
47
+ security: getWireSecurity(security)
48
+ };
49
+ const createResponse = await foundry_pack.Documents.create(this.app.config.osdkClient, request, {
50
+ preview: this.config.usePreviewApi ?? DEFAULT_USE_PREVIEW_API
51
+ });
52
+ const documentId = createResponse.id;
53
+ const docRef = this.createDocRef(documentId, schema);
54
+ return docRef;
55
+ };
56
+ onMetadataSubscriptionOpened(internalDoc, docRef) {
57
+ if (internalDoc.metadataStatus.load !== pack_state_core.DocumentLoadStatus.UNLOADED) {
58
+ throw new Error(`Cannot subscribe to document metadata when status is ${internalDoc.metadataStatus.load}`);
59
+ }
60
+ this.updateMetadataStatus(internalDoc, docRef, {
61
+ load: pack_state_core.DocumentLoadStatus.LOADING
62
+ });
63
+ foundry_pack.Documents.get(this.app.config.osdkClient, docRef.id, {
64
+ preview: this.config.usePreviewApi ?? DEFAULT_USE_PREVIEW_API
65
+ }).then((document) => {
66
+ const metadata = {
67
+ documentTypeName: document.documentTypeName,
68
+ name: document.name,
69
+ ontologyRid: "unknown",
70
+ security: {
71
+ discretionary: {
72
+ owners: []
73
+ },
74
+ mandatory: {}
75
+ }
76
+ };
77
+ internalDoc.metadata = metadata;
78
+ this.notifyMetadataSubscribers(internalDoc, docRef, metadata);
79
+ this.updateMetadataStatus(internalDoc, docRef, {
80
+ load: pack_state_core.DocumentLoadStatus.LOADED
81
+ });
82
+ }).catch((e) => {
83
+ const error = new Error("Failed to load document metadata", {
84
+ cause: e
85
+ });
86
+ this.updateMetadataStatus(internalDoc, docRef, {
87
+ error,
88
+ load: pack_state_core.DocumentLoadStatus.ERROR
89
+ });
90
+ });
91
+ }
92
+ onDataSubscriptionOpened(internalDoc, docRef) {
93
+ if (internalDoc.syncSession != null) {
94
+ throw new Error("Document data subscription already opened");
95
+ }
96
+ internalDoc.syncSession = this.eventService.startDocumentSync(docRef.id, internalDoc.yDoc, (status) => {
97
+ this.updateDataStatus(internalDoc, docRef, status);
98
+ });
99
+ }
100
+ onMetadataSubscriptionClosed(_internalDoc, _docRef) {
101
+ }
102
+ onDataSubscriptionClosed(internalDoc, _docRef) {
103
+ if (internalDoc.syncSession) {
104
+ this.eventService.stopDocumentSync(internalDoc.syncSession);
105
+ internalDoc.syncSession = void 0;
106
+ }
107
+ }
108
+ };
109
+ function mutableArray(array) {
110
+ return array == null ? [] : array;
111
+ }
112
+ function getWireSecurity(security) {
113
+ return {
114
+ discretionary: {
115
+ editors: [...security.discretionary.editors ?? []],
116
+ owners: [...security.discretionary.owners],
117
+ viewers: [...security.discretionary.viewers ?? []]
118
+ },
119
+ mandatory: {
120
+ classification: mutableArray(security.mandatory.classification),
121
+ markings: mutableArray(security.mandatory.markings)
122
+ }
123
+ };
124
+ }
125
+
126
+ exports.createFoundryDocumentServiceConfig = createFoundryDocumentServiceConfig;
127
+ //# sourceMappingURL=index.cjs.map
128
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/FoundryDocumentService.ts"],"names":["createDocumentServiceConfig","config","createFoundryEventService","BaseYjsDocumentService","Documents","DocumentLoadStatus"],"mappings":";;;;;;;AAmBA,IAAM,uBAAA,GAA0B,IAAA;AACzB,SAAS,kCAAA,CAAmC,MAAA,GAAS,EAAC,EAAG;AAC9D,EAAA,OAAOA,2CAAA,CAA4B,CAAC,GAAA,EAAKC,OAAAA,KAAW,qCAAqC,GAAA,EAAKA,OAAM,GAAG,MAAM,CAAA;AAC/G;AACO,SAAS,oCAAA,CAAqC,GAAA,EAAK,MAAA,EAAQ,YAAA,EAAc;AAC9E,EAAA,OAAO,IAAI,sBAAA,CAAuB,GAAA,EAAK,QAAwBC,iDAAA,CAA0B,GAAG,CAAC,CAAA;AAC/F;AACO,IAAM,sBAAA,GAAN,cAAqCC,sCAAA,CAAuB;AAAA,EACjE,WAAA,CAAY,GAAA,EAAK,MAAA,EAAQ,YAAA,EAAc;AACrC,IAAA,KAAA,CAAM,KAAK,GAAA,CAAI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,gBAAgB,QAAA,EAAU;AACjC,EAAA,OAAO;AAAA,IACL,aAAA,EAAe;AAAA,MACb,SAAS,CAAC,GAAI,SAAS,aAAA,CAAc,OAAA,IAAW,EAAG,CAAA;AAAA,MACnD,MAAA,EAAQ,CAAC,GAAG,QAAA,CAAS,cAAc,MAAM,CAAA;AAAA,MACzC,SAAS,CAAC,GAAI,SAAS,aAAA,CAAc,OAAA,IAAW,EAAG;AAAA,KACrD;AAAA,IACA,SAAA,EAAW;AAAA,MACT,cAAA,EAAgB,YAAA,CAAa,QAAA,CAAS,SAAA,CAAU,cAAc,CAAA;AAAA,MAC9D,QAAA,EAAU,YAAA,CAAa,QAAA,CAAS,SAAA,CAAU,QAAQ;AAAA;AACpD,GACF;AACF","file":"index.cjs","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Documents } from \"@osdk/foundry.pack\";\nimport { BaseYjsDocumentService, createDocumentServiceConfig, DocumentLoadStatus } from \"@palantir/pack.state.core\";\nimport { createFoundryEventService } from \"@palantir/pack.state.foundry-event\";\nconst DEFAULT_USE_PREVIEW_API = true;\nexport function createFoundryDocumentServiceConfig(config = {}) {\n return createDocumentServiceConfig((app, config) => internalCreateFoundryDocumentService(app, config), config);\n}\nexport function internalCreateFoundryDocumentService(app, config, eventService) {\n return new FoundryDocumentService(app, config, eventService ?? createFoundryEventService(app));\n}\nexport class FoundryDocumentService extends BaseYjsDocumentService {\n constructor(app, config, eventService) {\n super(app, app.config.logger.child({}, {\n level: \"debug\",\n msgPrefix: \"FoundryDocumentService\"\n }));\n this.config = config;\n this.eventService = eventService;\n }\n createInternalDoc(ref, metadata, initialYDoc) {\n return {\n ...this.createBaseInternalDoc(ref, metadata, initialYDoc),\n syncSession: undefined\n };\n }\n get hasMetadataSubscriptions() {\n return Array.from(this.documents.values()).some(doc => this.hasSubscriptions(doc) && doc.metadataSubscribers.size > 0);\n }\n get hasStateSubscriptions() {\n return Array.from(this.documents.values()).some(doc => this.hasSubscriptions(doc) && doc.docStateSubscribers.size > 0);\n }\n createDocument = async (metadata, schema) => {\n const {\n documentTypeName,\n name,\n ontologyRid,\n security\n } = metadata;\n const request = {\n documentTypeName: documentTypeName,\n name: name,\n ontologyRid: ontologyRid,\n security: getWireSecurity(security)\n };\n const createResponse = await Documents.create(this.app.config.osdkClient, request, {\n preview: this.config.usePreviewApi ?? DEFAULT_USE_PREVIEW_API\n });\n const documentId = createResponse.id;\n const docRef = this.createDocRef(documentId, schema);\n return docRef;\n };\n onMetadataSubscriptionOpened(internalDoc, docRef) {\n if (internalDoc.metadataStatus.load !== DocumentLoadStatus.UNLOADED) {\n throw new Error(`Cannot subscribe to document metadata when status is ${internalDoc.metadataStatus.load}`);\n }\n this.updateMetadataStatus(internalDoc, docRef, {\n load: DocumentLoadStatus.LOADING\n });\n Documents.get(this.app.config.osdkClient, docRef.id, {\n preview: this.config.usePreviewApi ?? DEFAULT_USE_PREVIEW_API\n }).then(document => {\n const metadata = {\n documentTypeName: document.documentTypeName,\n name: document.name,\n ontologyRid: \"unknown\",\n security: {\n discretionary: {\n owners: []\n },\n mandatory: {}\n }\n };\n internalDoc.metadata = metadata;\n this.notifyMetadataSubscribers(internalDoc, docRef, metadata);\n this.updateMetadataStatus(internalDoc, docRef, {\n load: DocumentLoadStatus.LOADED\n });\n }).catch(e => {\n const error = new Error(\"Failed to load document metadata\", {\n cause: e\n });\n this.updateMetadataStatus(internalDoc, docRef, {\n error,\n load: DocumentLoadStatus.ERROR\n });\n });\n }\n onDataSubscriptionOpened(internalDoc, docRef) {\n if (internalDoc.syncSession != null) {\n throw new Error(\"Document data subscription already opened\");\n }\n internalDoc.syncSession = this.eventService.startDocumentSync(docRef.id, internalDoc.yDoc, status => {\n this.updateDataStatus(internalDoc, docRef, status);\n });\n }\n onMetadataSubscriptionClosed(_internalDoc, _docRef) {}\n onDataSubscriptionClosed(internalDoc, _docRef) {\n if (internalDoc.syncSession) {\n this.eventService.stopDocumentSync(internalDoc.syncSession);\n internalDoc.syncSession = undefined;\n }\n }\n}\nfunction mutableArray(array) {\n return array == null ? [] : array;\n}\nfunction getWireSecurity(security) {\n return {\n discretionary: {\n editors: [...(security.discretionary.editors ?? [])],\n owners: [...security.discretionary.owners],\n viewers: [...(security.discretionary.viewers ?? [])]\n },\n mandatory: {\n classification: mutableArray(security.mandatory.classification),\n markings: mutableArray(security.mandatory.markings)\n }\n };\n}"]}
@@ -0,0 +1,9 @@
1
+ import { ModuleConfigTuple } from '@palantir/pack.core';
2
+ import { DocumentService } from '@palantir/pack.state.core';
3
+
4
+ interface FoundryDocumentServiceConfig {
5
+ readonly usePreviewApi?: boolean;
6
+ }
7
+ declare function createFoundryDocumentServiceConfig(config?: FoundryDocumentServiceConfig): ModuleConfigTuple<DocumentService>;
8
+
9
+ export { createFoundryDocumentServiceConfig };
@@ -0,0 +1,126 @@
1
+ import { Documents } from '@osdk/foundry.pack';
2
+ import { createDocumentServiceConfig, BaseYjsDocumentService, DocumentLoadStatus } from '@palantir/pack.state.core';
3
+ import { createFoundryEventService } from '@palantir/pack.state.foundry-event';
4
+
5
+ // src/FoundryDocumentService.ts
6
+ var DEFAULT_USE_PREVIEW_API = true;
7
+ function createFoundryDocumentServiceConfig(config = {}) {
8
+ return createDocumentServiceConfig((app, config2) => internalCreateFoundryDocumentService(app, config2), config);
9
+ }
10
+ function internalCreateFoundryDocumentService(app, config, eventService) {
11
+ return new FoundryDocumentService(app, config, createFoundryEventService(app));
12
+ }
13
+ var FoundryDocumentService = class extends BaseYjsDocumentService {
14
+ constructor(app, config, eventService) {
15
+ super(app, app.config.logger.child({}, {
16
+ level: "debug",
17
+ msgPrefix: "FoundryDocumentService"
18
+ }));
19
+ this.config = config;
20
+ this.eventService = eventService;
21
+ }
22
+ createInternalDoc(ref, metadata, initialYDoc) {
23
+ return {
24
+ ...this.createBaseInternalDoc(ref, metadata, initialYDoc),
25
+ syncSession: void 0
26
+ };
27
+ }
28
+ get hasMetadataSubscriptions() {
29
+ return Array.from(this.documents.values()).some((doc) => this.hasSubscriptions(doc) && doc.metadataSubscribers.size > 0);
30
+ }
31
+ get hasStateSubscriptions() {
32
+ return Array.from(this.documents.values()).some((doc) => this.hasSubscriptions(doc) && doc.docStateSubscribers.size > 0);
33
+ }
34
+ createDocument = async (metadata, schema) => {
35
+ const {
36
+ documentTypeName,
37
+ name,
38
+ ontologyRid,
39
+ security
40
+ } = metadata;
41
+ const request = {
42
+ documentTypeName,
43
+ name,
44
+ ontologyRid,
45
+ security: getWireSecurity(security)
46
+ };
47
+ const createResponse = await Documents.create(this.app.config.osdkClient, request, {
48
+ preview: this.config.usePreviewApi ?? DEFAULT_USE_PREVIEW_API
49
+ });
50
+ const documentId = createResponse.id;
51
+ const docRef = this.createDocRef(documentId, schema);
52
+ return docRef;
53
+ };
54
+ onMetadataSubscriptionOpened(internalDoc, docRef) {
55
+ if (internalDoc.metadataStatus.load !== DocumentLoadStatus.UNLOADED) {
56
+ throw new Error(`Cannot subscribe to document metadata when status is ${internalDoc.metadataStatus.load}`);
57
+ }
58
+ this.updateMetadataStatus(internalDoc, docRef, {
59
+ load: DocumentLoadStatus.LOADING
60
+ });
61
+ Documents.get(this.app.config.osdkClient, docRef.id, {
62
+ preview: this.config.usePreviewApi ?? DEFAULT_USE_PREVIEW_API
63
+ }).then((document) => {
64
+ const metadata = {
65
+ documentTypeName: document.documentTypeName,
66
+ name: document.name,
67
+ ontologyRid: "unknown",
68
+ security: {
69
+ discretionary: {
70
+ owners: []
71
+ },
72
+ mandatory: {}
73
+ }
74
+ };
75
+ internalDoc.metadata = metadata;
76
+ this.notifyMetadataSubscribers(internalDoc, docRef, metadata);
77
+ this.updateMetadataStatus(internalDoc, docRef, {
78
+ load: DocumentLoadStatus.LOADED
79
+ });
80
+ }).catch((e) => {
81
+ const error = new Error("Failed to load document metadata", {
82
+ cause: e
83
+ });
84
+ this.updateMetadataStatus(internalDoc, docRef, {
85
+ error,
86
+ load: DocumentLoadStatus.ERROR
87
+ });
88
+ });
89
+ }
90
+ onDataSubscriptionOpened(internalDoc, docRef) {
91
+ if (internalDoc.syncSession != null) {
92
+ throw new Error("Document data subscription already opened");
93
+ }
94
+ internalDoc.syncSession = this.eventService.startDocumentSync(docRef.id, internalDoc.yDoc, (status) => {
95
+ this.updateDataStatus(internalDoc, docRef, status);
96
+ });
97
+ }
98
+ onMetadataSubscriptionClosed(_internalDoc, _docRef) {
99
+ }
100
+ onDataSubscriptionClosed(internalDoc, _docRef) {
101
+ if (internalDoc.syncSession) {
102
+ this.eventService.stopDocumentSync(internalDoc.syncSession);
103
+ internalDoc.syncSession = void 0;
104
+ }
105
+ }
106
+ };
107
+ function mutableArray(array) {
108
+ return array == null ? [] : array;
109
+ }
110
+ function getWireSecurity(security) {
111
+ return {
112
+ discretionary: {
113
+ editors: [...security.discretionary.editors ?? []],
114
+ owners: [...security.discretionary.owners],
115
+ viewers: [...security.discretionary.viewers ?? []]
116
+ },
117
+ mandatory: {
118
+ classification: mutableArray(security.mandatory.classification),
119
+ markings: mutableArray(security.mandatory.markings)
120
+ }
121
+ };
122
+ }
123
+
124
+ export { createFoundryDocumentServiceConfig };
125
+ //# sourceMappingURL=index.js.map
126
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/FoundryDocumentService.ts"],"names":["config"],"mappings":";;;;;AAmBA,IAAM,uBAAA,GAA0B,IAAA;AACzB,SAAS,kCAAA,CAAmC,MAAA,GAAS,EAAC,EAAG;AAC9D,EAAA,OAAO,2BAAA,CAA4B,CAAC,GAAA,EAAKA,OAAAA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EAAS;AAAA,EAAC;AAAA,EACrD,wBAAA,CAAyB,aAAa,OAAA,EAAS;AAC7C,IAAA,IAAI,YAAY,WAAA,EAAa;AAC3B,MAAA,IAAA,CAAK,YAAA,CAAa,gBAAA,CAAiB,WAAA,CAAY,WAAW,CAAA;AAC1D,MAAA,WAAA,CAAY,WAAA,GAAc,MAAA;AAAA,IAC5B;AAAA,EACF;AACF,CAAA;AACA,SAAS,aAAa,KAAA,EAAO;AAC3B,EAAA,OAAO,KAAA,IAAS,IAAA,GAAO,EAAC,GAAI,KAAA;AAC9B;AACA,SAAS,gBAAgB,QAAA,EAAU;AACjC,EAAA,OAAO;AAAA,IACL,aAAA,EAAe;AAAA,MACb,SAAS,CAAC,GAAI,SAAS,aAAA,CAAc,OAAA,IAAW,EAAG,CAAA;AAAA,MACnD,MAAA,EAAQ,CAAC,GAAG,QAAA,CAAS,cAAc,MAAM,CAAA;AAAA,MACzC,SAAS,CAAC,GAAI,SAAS,aAAA,CAAc,OAAA,IAAW,EAAG;AAAA,KACrD;AAAA,IACA,SAAA,EAAW;AAAA,MACT,cAAA,EAAgB,YAAA,CAAa,QAAA,CAAS,SAAA,CAAU,cAAc,CAAA;AAAA,MAC9D,QAAA,EAAU,YAAA,CAAa,QAAA,CAAS,SAAA,CAAU,QAAQ;AAAA;AACpD,GACF;AACF","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Documents } from \"@osdk/foundry.pack\";\nimport { BaseYjsDocumentService, createDocumentServiceConfig, DocumentLoadStatus } from \"@palantir/pack.state.core\";\nimport { createFoundryEventService } from \"@palantir/pack.state.foundry-event\";\nconst DEFAULT_USE_PREVIEW_API = true;\nexport function createFoundryDocumentServiceConfig(config = {}) {\n return createDocumentServiceConfig((app, config) => internalCreateFoundryDocumentService(app, config), config);\n}\nexport function internalCreateFoundryDocumentService(app, config, eventService) {\n return new FoundryDocumentService(app, config, eventService ?? createFoundryEventService(app));\n}\nexport class FoundryDocumentService extends BaseYjsDocumentService {\n constructor(app, config, eventService) {\n super(app, app.config.logger.child({}, {\n level: \"debug\",\n msgPrefix: \"FoundryDocumentService\"\n }));\n this.config = config;\n this.eventService = eventService;\n }\n createInternalDoc(ref, metadata, initialYDoc) {\n return {\n ...this.createBaseInternalDoc(ref, metadata, initialYDoc),\n syncSession: undefined\n };\n }\n get hasMetadataSubscriptions() {\n return Array.from(this.documents.values()).some(doc => this.hasSubscriptions(doc) && doc.metadataSubscribers.size > 0);\n }\n get hasStateSubscriptions() {\n return Array.from(this.documents.values()).some(doc => this.hasSubscriptions(doc) && doc.docStateSubscribers.size > 0);\n }\n createDocument = async (metadata, schema) => {\n const {\n documentTypeName,\n name,\n ontologyRid,\n security\n } = metadata;\n const request = {\n documentTypeName: documentTypeName,\n name: name,\n ontologyRid: ontologyRid,\n security: getWireSecurity(security)\n };\n const createResponse = await Documents.create(this.app.config.osdkClient, request, {\n preview: this.config.usePreviewApi ?? DEFAULT_USE_PREVIEW_API\n });\n const documentId = createResponse.id;\n const docRef = this.createDocRef(documentId, schema);\n return docRef;\n };\n onMetadataSubscriptionOpened(internalDoc, docRef) {\n if (internalDoc.metadataStatus.load !== DocumentLoadStatus.UNLOADED) {\n throw new Error(`Cannot subscribe to document metadata when status is ${internalDoc.metadataStatus.load}`);\n }\n this.updateMetadataStatus(internalDoc, docRef, {\n load: DocumentLoadStatus.LOADING\n });\n Documents.get(this.app.config.osdkClient, docRef.id, {\n preview: this.config.usePreviewApi ?? DEFAULT_USE_PREVIEW_API\n }).then(document => {\n const metadata = {\n documentTypeName: document.documentTypeName,\n name: document.name,\n ontologyRid: \"unknown\",\n security: {\n discretionary: {\n owners: []\n },\n mandatory: {}\n }\n };\n internalDoc.metadata = metadata;\n this.notifyMetadataSubscribers(internalDoc, docRef, metadata);\n this.updateMetadataStatus(internalDoc, docRef, {\n load: DocumentLoadStatus.LOADED\n });\n }).catch(e => {\n const error = new Error(\"Failed to load document metadata\", {\n cause: e\n });\n this.updateMetadataStatus(internalDoc, docRef, {\n error,\n load: DocumentLoadStatus.ERROR\n });\n });\n }\n onDataSubscriptionOpened(internalDoc, docRef) {\n if (internalDoc.syncSession != null) {\n throw new Error(\"Document data subscription already opened\");\n }\n internalDoc.syncSession = this.eventService.startDocumentSync(docRef.id, internalDoc.yDoc, status => {\n this.updateDataStatus(internalDoc, docRef, status);\n });\n }\n onMetadataSubscriptionClosed(_internalDoc, _docRef) {}\n onDataSubscriptionClosed(internalDoc, _docRef) {\n if (internalDoc.syncSession) {\n this.eventService.stopDocumentSync(internalDoc.syncSession);\n internalDoc.syncSession = undefined;\n }\n }\n}\nfunction mutableArray(array) {\n return array == null ? [] : array;\n}\nfunction getWireSecurity(security) {\n return {\n discretionary: {\n editors: [...(security.discretionary.editors ?? [])],\n owners: [...security.discretionary.owners],\n viewers: [...(security.discretionary.viewers ?? [])]\n },\n mandatory: {\n classification: mutableArray(security.mandatory.classification),\n markings: mutableArray(security.mandatory.markings)\n }\n };\n}"]}
@@ -0,0 +1,28 @@
1
+ import type { ModuleConfigTuple, PackAppInternal } from "@palantir/pack.core";
2
+ import type { DocumentMetadata, DocumentRef, DocumentSchema } from "@palantir/pack.document-schema.model-types";
3
+ import type { DocumentService, InternalYjsDoc } from "@palantir/pack.state.core";
4
+ import { BaseYjsDocumentService } from "@palantir/pack.state.core";
5
+ import type { FoundryEventService, SyncSession } from "@palantir/pack.state.foundry-event";
6
+ import type * as y from "yjs";
7
+ interface FoundryDocumentServiceConfig {
8
+ readonly usePreviewApi?: boolean;
9
+ }
10
+ export declare function createFoundryDocumentServiceConfig(config?: FoundryDocumentServiceConfig): ModuleConfigTuple<DocumentService>;
11
+ export declare function internalCreateFoundryDocumentService(app: PackAppInternal, config: FoundryDocumentServiceConfig, eventService?: FoundryEventService): FoundryDocumentService;
12
+ interface FoundryInternalDoc extends InternalYjsDoc {
13
+ syncSession?: SyncSession;
14
+ }
15
+ export declare class FoundryDocumentService extends BaseYjsDocumentService<FoundryInternalDoc> {
16
+ readonly config: FoundryDocumentServiceConfig;
17
+ readonly eventService: FoundryEventService;
18
+ constructor(app: PackAppInternal, config: FoundryDocumentServiceConfig, eventService: FoundryEventService);
19
+ protected createInternalDoc(ref: DocumentRef, metadata: DocumentMetadata | undefined, initialYDoc?: y.Doc): FoundryInternalDoc;
20
+ get hasMetadataSubscriptions(): boolean;
21
+ get hasStateSubscriptions(): boolean;
22
+ readonly createDocument: <T extends DocumentSchema>(metadata: DocumentMetadata, schema: T) => Promise<DocumentRef<T>>;
23
+ protected onMetadataSubscriptionOpened(internalDoc: FoundryInternalDoc, docRef: DocumentRef): void;
24
+ protected onDataSubscriptionOpened(internalDoc: FoundryInternalDoc, docRef: DocumentRef): void;
25
+ protected onMetadataSubscriptionClosed(_internalDoc: FoundryInternalDoc, _docRef: DocumentRef): void;
26
+ protected onDataSubscriptionClosed(internalDoc: FoundryInternalDoc, _docRef: DocumentRef): void;
27
+ }
28
+ export {};
@@ -0,0 +1 @@
1
+ {"mappings":"AAkBA,cAAc,mBAAmB,uBAAuB;AACxD,cAEE,kBACA,aACA,sBACK;AACP,cAAc,iBAAiB,sBAAsB;AACrD,SACE,8BAGK;AACP,cAAc,qBAAqB,mBAAmB;AAEtD,iBAAiB,OAAO;UAId,6BAA6B;UAC5B;;AAGX,OAAO,iBAAS,mCACd,SAAQ,+BACP,kBAAkB;AAQrB,OAAO,iBAAS,qCACd,KAAK,iBACL,QAAQ,8BACR,eAAe,sBACd;UAQO,2BAA2B,eAAe;CAClD,cAAc;;AAGhB,OAAO,cAAM,+BAA+B,uBAAuB,oBAAoB;CAGnF,iBAAiB;CACjB,uBAAuB;CAHzB,YACE,KAAK,iBACL,AAASA,QAAQ,8BACjB,AAASC,cAAc;CAQzB,UAAU,kBACR,KAAK,aACL,UAAU,8BACV,cAAc,EAAE,MACf;CAOH,IAAI;CAMJ,IAAI;CAMJ,SAAS,iBAAwB,UAAU,gBACzC,UAAU,kBACV,QAAQ,MACP,QAAQ,YAAY;CAkBvB,UAAU,6BACR,aAAa,oBACb,QAAQ;CAsCV,UAAU,yBACR,aAAa,oBACb,QAAQ;CAeV,UAAU,6BACR,cAAc,oBACd,SAAS;CAIX,UAAU,yBACR,aAAa,oBACb,SAAS","names":["config: FoundryDocumentServiceConfig","eventService: FoundryEventService"],"sources":["../../src/FoundryDocumentService.ts"],"version":3,"file":"FoundryDocumentService.d.ts"}
@@ -0,0 +1 @@
1
+ {"mappings":"","names":[],"sources":["../../../src/__tests__/FoundryStatusTracking.test.ts"],"version":3,"file":"FoundryStatusTracking.test.d.ts"}
@@ -0,0 +1 @@
1
+ export { createFoundryDocumentServiceConfig } from "./FoundryDocumentService.js";
@@ -0,0 +1 @@
1
+ {"mappings":"AAgBA,SAAS,0CAA0C","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@palantir/pack.state.foundry",
3
+ "version": "0.0.1-beta.1",
4
+ "description": "PACK State service that integrates with Palantir Foundry platform APIs.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/palantir/pack.git"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "browser": "./build/browser/index.js",
13
+ "import": {
14
+ "types": "./build/types/index.d.ts",
15
+ "default": "./build/esm/index.js"
16
+ },
17
+ "require": "./build/cjs/index.js",
18
+ "default": "./build/browser/index.js"
19
+ },
20
+ "./*": {
21
+ "browser": "./build/browser/public/*.js",
22
+ "import": {
23
+ "types": "./build/types/public/*.d.ts",
24
+ "default": "./build/js/public/*.js"
25
+ },
26
+ "require": "./build/cjs/public/*.js",
27
+ "default": "./build/browser/public/*.js"
28
+ }
29
+ },
30
+ "dependencies": {
31
+ "@osdk/api": "~2.4.2",
32
+ "@osdk/foundry.pack": "~2.38.0",
33
+ "conjure-client": "^2.15.0",
34
+ "remeda": "^2.32.0",
35
+ "yjs": "^13.6.27",
36
+ "@palantir/pack.auth": "0.0.1-beta.1",
37
+ "@palantir/pack.core": "0.1.0-beta.2",
38
+ "@palantir/pack.document-schema.model-types": "0.1.0-beta.3",
39
+ "@palantir/pack.state.core": "0.1.0-beta.2",
40
+ "@palantir/pack.state.foundry-event": "0.0.1-beta.1"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^20.19.17",
44
+ "rimraf": "^6.0.1",
45
+ "tslib": "^2.8.1",
46
+ "typescript": "^5.9.2",
47
+ "vitest-mock-extended": "^3.1.0",
48
+ "@palantir/pack.monorepo.tsconfig": "~0.4.0-beta.1"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "keywords": [
54
+ "pack"
55
+ ],
56
+ "main": "./build/cjs/index.js",
57
+ "module": "./build/esm/index.js",
58
+ "types": "./build/cjs/index.d.ts",
59
+ "type": "module",
60
+ "scripts": {
61
+ "clean": "rimraf .turbo build dist lib test-output *.tgz tsconfig.tsbuildinfo",
62
+ "lint": "eslint ./src ; dprint check --config $(find-up dprint.json) --allow-no-files",
63
+ "lint:fix": "eslint ./src --fix ; dprint fmt --config $(find-up dprint.json) --allow-no-files",
64
+ "test": "vitest run --passWithNoTests -u",
65
+ "test:watch": "vitest --passWithNoTests",
66
+ "transpileBrowser": "monorepo-transpile -f esm -m bundle -t browser",
67
+ "transpileCjs": "monorepo-transpile -f cjs -m bundle -t node",
68
+ "transpileEsm": "monorepo-transpile -f esm -m bundle -t node",
69
+ "transpileTypes": "monorepo-transpile -f esm -m types -t node",
70
+ "typecheck": "tsc --noEmit --emitDeclarationOnly false"
71
+ }
72
+ }