@palantir/pack.document-schema.model-types 0.1.0-beta.3 → 0.1.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.
- package/.turbo/turbo-lint.log +2 -2
- package/.turbo/turbo-transpileBrowser.log +1 -1
- package/.turbo/turbo-transpileCjs.log +1 -1
- package/.turbo/turbo-transpileEsm.log +1 -1
- package/.turbo/turbo-transpileTypes.log +1 -1
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +27 -0
- package/build/browser/index.js +29 -5
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs +30 -4
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +517 -39
- package/build/esm/index.js +29 -5
- package/build/esm/index.js.map +1 -1
- package/build/types/__tests__/Metadata.test.d.ts +1 -0
- package/build/types/__tests__/Metadata.test.d.ts.map +1 -0
- package/build/types/index.d.ts +6 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/types/ActivityEvent.d.ts +64 -0
- package/build/types/types/ActivityEvent.d.ts.map +1 -0
- package/build/types/types/DocumentRef.d.ts +199 -5
- package/build/types/types/DocumentRef.d.ts.map +1 -1
- package/build/types/types/DocumentSchema.d.ts +6 -0
- package/build/types/types/DocumentSchema.d.ts.map +1 -1
- package/build/types/types/Model.d.ts +13 -0
- package/build/types/types/Model.d.ts.map +1 -1
- package/build/types/types/PresenceEvent.d.ts +73 -0
- package/build/types/types/PresenceEvent.d.ts.map +1 -0
- package/build/types/types/RecordCollectionRef.d.ts +54 -0
- package/build/types/types/RecordCollectionRef.d.ts.map +1 -1
- package/build/types/types/RecordRef.d.ts +71 -0
- package/build/types/types/RecordRef.d.ts.map +1 -1
- package/build/types/types/Unsubscribe.d.ts +3 -0
- package/build/types/types/Unsubscribe.d.ts.map +1 -1
- package/build/types/types/UserRef.d.ts +5 -0
- package/build/types/types/UserRef.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/Metadata.test.ts +43 -0
- package/src/index.ts +19 -2
- package/src/types/ActivityEvent.ts +88 -0
- package/src/types/DocumentRef.ts +218 -8
- package/src/types/DocumentSchema.ts +6 -0
- package/src/types/Metadata.ts +20 -5
- package/src/types/Model.ts +14 -0
- package/src/types/PresenceEvent.ts +102 -0
- package/src/types/RecordCollectionRef.ts +54 -0
- package/src/types/RecordRef.ts +74 -0
- package/src/types/Unsubscribe.ts +3 -0
- package/src/types/UserRef.ts +5 -0
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/DocumentRef.ts","../../src/types/MediaRef.ts","../../src/types/Metadata.ts","../../src/types/Model.ts","../../src/types/ObjectRef.ts","../../src/types/RecordCollectionRef.ts","../../src/types/RecordRef.ts","../../src/types/UserRef.ts"],"names":[],"mappings":";AAgBO,IAAM,gBAAA,GAAmB,OAAO,kBAAkB;;;ACAlD,IAAM,aAAA,GAAgB,OAAO,eAAe;;;ACA5C,IAAM,QAAA,GAAW,OAAO,yCAAyC;AACjE,SAAS,YAAY,GAAA,EAAK;AAE/B,EAAA,MAAM,QAAA,GAAW,IAAI,QAAQ,CAAA;AAC7B,EAAA,IAAI,YAAY,IAAA,EAAM;AACpB,IAAA,MAAM,IAAI,MAAM,+BAA+B,CAAA;AAAA,EACjD;AACA,EAAA,OAAO,QAAA;AACT;;;ACDO,IAAM,eAAA,GAAkB;AAAA,EAC7B,OAAA,EAAS,QAAA;AAAA,EACT,SAAA,EAAW,UAAA;AAAA,EACX,UAAA,EAAY,WAAA;AAAA,EACZ,QAAA,EAAU;AACZ;;;ACZO,IAAM,cAAA,GAAiB,OAAO,gBAAgB;;;ACA9C,IAAM,wBAAA,GAA2B,OAAO,0BAA0B;;;ACAlE,IAAM,cAAA,GAAiB,OAAO,gBAAgB;;;ACA9C,IAAM,YAAA,GAAe,OAAO,cAAc","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\nexport const DocumentRefBrand = Symbol(\"pack:DocumentRef\");","/*\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\nexport const MediaRefBrand = Symbol(\"pack:MediaRef\");\n\n/**\n * @experimental\n */","/*\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\nexport const Metadata = Symbol(\"@palantir/pack.document-schema/metadata\");\nexport function getMetadata(obj) {\n // TS always treats symbol keys as optional\n const metadata = obj[Metadata];\n if (metadata == null) {\n throw new Error(\"Object does not have metadata\");\n }\n return metadata;\n}","/*\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\n/**\n * A Model defines the structure of a document record or union.\n *\n * It includes a zod schema for validation and type information.\n */\n// TODO: I think we can/should hide the zod types\n\nexport const ExternalRefType = {\n DOC_REF: \"docRef\",\n MEDIA_REF: \"mediaRef\",\n OBJECT_REF: \"objectRef\",\n USER_REF: \"userRef\"\n};","/*\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\nexport const ObjectRefBrand = Symbol(\"pack:ObjectRef\");\n\n/**\n * @experimental\n */","/*\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\nexport const RecordCollectionRefBrand = Symbol(\"pack:RecordCollectionRef\");","/*\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\nexport const RecordRefBrand = Symbol(\"pack:RecordRef\");","/*\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\nexport const UserRefBrand = Symbol(\"pack:UserRef\");"]}
|
|
1
|
+
{"version":3,"sources":["../../src/types/ActivityEvent.ts","../../src/types/DocumentRef.ts","../../src/types/MediaRef.ts","../../src/types/Metadata.ts","../../src/types/Model.ts","../../src/types/ObjectRef.ts","../../src/types/PresenceEvent.ts","../../src/types/RecordCollectionRef.ts","../../src/types/RecordRef.ts","../../src/types/UserRef.ts"],"names":[],"mappings":";AAgBO,IAAM,qBAAA,GAAwB;AAAA,EACnC,YAAA,EAAc,aAAA;AAAA,EACd,OAAA,EAAS;AACX;;;ACCO,IAAM,gBAAA,GAAmB,OAAO,kBAAkB;;;ACJlD,IAAM,aAAA,GAAgB,OAAO,eAAe;;;ACA5C,IAAM,QAAA,GAAW,OAAO,yCAAyC;AACjE,SAAS,YAAY,GAAA,EAAK;AAE/B,EAAA,MAAM,cAAA,GAAiB,IAAI,QAAQ,CAAA;AACnC,EAAA,IAAI,kBAAkB,IAAA,EAAM;AAC1B,IAAA,OAAO,cAAA;AAAA,EACT;AAIA,EAAA,MAAM,cAAA,GAAiB,SAAS,QAAA,EAAS;AACzC,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,qBAAA,CAAsB,GAAG,CAAA;AACnD,EAAA,KAAA,MAAW,aAAa,UAAA,EAAY;AAClC,IAAA,IAAI,SAAA,CAAU,QAAA,EAAS,KAAM,cAAA,EAAgB;AAC3C,MAAA,MAAM,gBAAA,GAAmB,IAAI,SAAS,CAAA;AACtC,MAAA,IAAI,oBAAoB,IAAA,EAAM;AAC5B,QAAA,OAAO,gBAAA;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACA,EAAA,MAAM,IAAI,MAAM,+BAA+B,CAAA;AACjD;;;ACVO,IAAM,eAAA,GAAkB;AAAA,EAC7B,OAAA,EAAS,QAAA;AAAA,EACT,SAAA,EAAW,UAAA;AAAA,EACX,UAAA,EAAY,WAAA;AAAA,EACZ,QAAA,EAAU;AACZ;;;AChBO,IAAM,cAAA,GAAiB,OAAO,gBAAgB;;;ACA9C,IAAM,qBAAA,GAAwB;AAAA,EACnC,OAAA,EAAS,iBAAA;AAAA,EACT,QAAA,EAAU,kBAAA;AAAA,EACV,YAAA,EAAc,aAAA;AAAA,EACd,OAAA,EAAS;AACX;;;ACLO,IAAM,wBAAA,GAA2B,OAAO,0BAA0B;;;ACAlE,IAAM,cAAA,GAAiB,OAAO,gBAAgB;;;ACA9C,IAAM,YAAA,GAAe,OAAO,cAAc","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\nexport const ActivityEventDataType = {\n CUSTOM_EVENT: \"customEvent\",\n UNKNOWN: \"unknown\"\n};\n\n/**\n * Application specific custom activity event data, as described in a transaction edit,\n * using an application sdk's generated model types.\n *\n * @example\n * ```ts\n * const unsubscribe = docRef.onActivity((docRef, event) => {\n * console.log(\"Activity event:\", event);\n * });\n * // Submit an edit with a description to generate an activity event.\n * docRef.withTransaction(() => {\n * // make some edits to the document here\n * }, {\n * model: MyEventModel,\n * data: {\n * myDataField: \"some value\",\n * foo: 42,\n * },\n * });\n * ```\n */\n\n// TODO: add standard document activity events (need to be added to api types)\n\n/**\n * Fallback for unrecognized activity event types.\n *\n * This allows some flexibility with new event types added to the platform.\n * Likely unknown events represent a new platform event type and will be handled\n * in a future release of pack libraries and can be safely ignored by\n * applications.\n */\n\n/**\n * An event representing an activity that has occurred on a document. This\n * includes standard document events as well as custom application-specific\n * events describing document edits.\n *\n * ActivityEvents are useful for building activity feeds, or notifications.\n */","/*\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\n/**\n * Options for subscribing to presence events on a document.\n */\n\nexport const DocumentRefBrand = Symbol(\"pack:DocumentRef\");\n\n/**\n * A reference to a document in the Pack system.\n *\n * A documentRef returned by various interfaces from the pack app instance or\n * utilities such as react hooks from @palantir/pack.state.react provides\n * methods to interact with the document, such as subscribing to & making\n * changes to the document state and also related activity or presence events.\n *\n * A stable documentRef object is guaranteed for the same document id within the\n * same app instance.\n */","/*\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\nexport const MediaRefBrand = Symbol(\"pack:MediaRef\");\n\n/**\n * @experimental\n */","/*\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\nexport const Metadata = Symbol(\"@palantir/pack.document-schema/metadata\");\nexport function getMetadata(obj) {\n // First try the direct symbol access\n const directMetadata = obj[Metadata];\n if (directMetadata != null) {\n return directMetadata;\n }\n\n // Fallback: search for a symbol with matching string representation\n // If the different copies of this package are used, the symbol references will not match directly\n const metadataString = Metadata.toString();\n const symbolKeys = Object.getOwnPropertySymbols(obj);\n for (const symbolKey of symbolKeys) {\n if (symbolKey.toString() === metadataString) {\n const fallbackMetadata = obj[symbolKey];\n if (fallbackMetadata != null) {\n return fallbackMetadata;\n }\n }\n }\n throw new Error(\"Object does not have metadata\");\n}","/*\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\n/**\n * A Model defines the structure of a document record or union.\n *\n * It includes a zod schema for validation and type information.\n */\n// TODO: I think we can/should hide the zod types\n\n/**\n * Describes an edit made to a document.\n */\n\nexport const ExternalRefType = {\n DOC_REF: \"docRef\",\n MEDIA_REF: \"mediaRef\",\n OBJECT_REF: \"objectRef\",\n USER_REF: \"userRef\"\n};","/*\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\nexport const ObjectRefBrand = Symbol(\"pack:ObjectRef\");\n\n/**\n * @experimental\n */","/*\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\nexport const PresenceEventDataType = {\n ARRIVED: \"presenceArrived\",\n DEPARTED: \"presenceDeparted\",\n CUSTOM_EVENT: \"customEvent\",\n UNKNOWN: \"unknown\"\n};\n\n/**\n * Any client that subscribes to presence events via `DocumentRef.onPresence` will\n * be considered 'present' on the document, and trigger an 'arrived' presence event.\n * When they disconnect or unsubscribe from presence events, a 'departed' presence event\n * will be triggered.\n */\n\n/**\n * Any client that subscribes to presence events via `DocumentRef.onPresence` will\n * be considered 'present' on the document, and trigger an 'arrived' presence event.\n * When they disconnect or unsubscribe from presence events, a 'departed' presence event\n * will be triggered.\n */\n\n/**\n * Application specific custom presence event data.\n *\n * Each different model type used for presence is expected to update the latest\n * 'presence state' for that model type.\n *\n * For example, your app may have need to broadcast user cursor positions and\n * selection ranges as presence data. You could define your schema to include a\n * `CursorPosition` and `SelectionRange` record types, and set them\n * independently via `{@link DocumentRef.updateCustomPresence}`. Each model type\n * sent as a custom presence event should be considered a separate 'channel' of\n * presence data on this document.\n */\n\n/**\n * Fallback for unrecognized activity event types.\n *\n * This allows some flexibility with new event types added to the platform.\n * Likely unknown events represent a new platform event type and will be handled\n * in a future release of pack libraries and can be safely ignored by\n * applications.\n */\n\n/**\n * An event representing a transient awareness or presence change for a user on this document.\n * The presence channel is intended for ephemeral data such as user cursors, selections, or\n * other live collaboration indicators.\n *\n * PresenceEvents are not persisted in document history.\n *\n * When a client goes offline, its presence is considered departed and any presence events\n * associated with that user should be considered stale and / or cleared.\n */","/*\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\nexport const RecordCollectionRefBrand = Symbol(\"pack:RecordCollectionRef\");\n\n/**\n * A reference providing an API to interact with a collection of records in a document.\n */","/*\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\nexport const RecordRefBrand = Symbol(\"pack:RecordRef\");\n\n/**\n * A reference providing an API to interact with a specific record in a\n * document. This is the main interface for accessing and updating individual\n * records.\n *\n * These will be created by docRef or recordCollectionRef APIs for example and\n * should not be created manually. RecordRefs are stable objects that can be\n * used for reference equality checks.\n *\n * @example\n * ```ts\n * import { DocumentRef, DocumentSchema, MyModel } from \"@myapp/schema\";\n * import { app } from \"./appInstance\";\n *\n * const docRef = app.getDocRef<DocumentSchema>(someDocumentId);\n *\n * const recordRef = docRef.getRecords(MyModel).set(\"my-record-id\", { myFieldName: \"some value\", foo: 42 });\n *\n * // Or get a specific record.\n * const recordRef = docRef.getRecords(MyModel).get(\"my-record-id\");\n */","/*\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\nexport const UserRefBrand = Symbol(\"pack:UserRef\");\n\n/**\n * A reference providing an API to interact with a user.\n *\n * @experimental\n */"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"","names":[],"sources":["../../../src/__tests__/Metadata.test.ts"],"version":3,"file":"Metadata.test.d.ts"}
|
package/build/types/index.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
export { ActivityEventDataType } from "./types/ActivityEvent.js";
|
|
2
|
+
export type { ActivityEvent, ActivityEventData, ActivityEventDataCustom, ActivityEventDataUnknown, ActivityEventId } from "./types/ActivityEvent.js";
|
|
1
3
|
export type { DiscretionaryPrincipal, DiscretionaryPrincipal_All, DiscretionaryPrincipal_GroupId, DiscretionaryPrincipal_UserId, DocumentMetadata } from "./types/DocumentMetadata.js";
|
|
2
4
|
export { DocumentRefBrand } from "./types/DocumentRef.js";
|
|
3
|
-
export type { DocumentId, DocumentRef } from "./types/DocumentRef.js";
|
|
5
|
+
export type { DocumentId, DocumentRef, PresenceSubscriptionOptions } from "./types/DocumentRef.js";
|
|
4
6
|
export type { DocumentSchema, DocumentSchemaMetadata, DocumentState } from "./types/DocumentSchema.js";
|
|
5
7
|
export { MediaRefBrand } from "./types/MediaRef.js";
|
|
6
8
|
export type { MediaId, MediaRef } from "./types/MediaRef.js";
|
|
7
9
|
export { getMetadata, Metadata } from "./types/Metadata.js";
|
|
8
10
|
export type { WithMetadata } from "./types/Metadata.js";
|
|
9
11
|
export { ExternalRefType } from "./types/Model.js";
|
|
10
|
-
export type { Model, ModelData, ModelMetadata } from "./types/Model.js";
|
|
12
|
+
export type { EditDescription, Model, ModelData, ModelMetadata } from "./types/Model.js";
|
|
11
13
|
export { ObjectRefBrand } from "./types/ObjectRef.js";
|
|
12
14
|
export type { ObjectId, ObjectRef } from "./types/ObjectRef.js";
|
|
15
|
+
export { PresenceEventDataType } from "./types/PresenceEvent.js";
|
|
16
|
+
export type { PresenceEvent, PresenceEventData, PresenceEventDataArrived, PresenceEventDataCustom, PresenceEventDataDeparted, PresenceEventUnknown } from "./types/PresenceEvent.js";
|
|
13
17
|
export { RecordCollectionRefBrand } from "./types/RecordCollectionRef.js";
|
|
14
18
|
export type { RecordCollectionRef } from "./types/RecordCollectionRef.js";
|
|
15
19
|
export { RecordRefBrand } from "./types/RecordRef.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cACE,wBACA,4BACA,gCACA,+BACA,wBACK;AACP,SAAS,wBAAwB;AACjC,cAAc,YAAY,
|
|
1
|
+
{"mappings":"AAgBA,SAAS,6BAA6B;AACtC,cACE,eACA,mBACA,yBACA,0BACA,uBACK;AACP,cACE,wBACA,4BACA,gCACA,+BACA,wBACK;AACP,SAAS,wBAAwB;AACjC,cAAc,YAAY,aAAa,mCAAmC;AAC1E,cACE,gBACA,wBACA,qBACK;AACP,SAAS,qBAAqB;AAC9B,cAAc,SAAS,gBAAgB;AACvC,SAAS,aAAa,gBAAgB;AACtC,cAAc,oBAAoB;AAClC,SAAS,uBAAuB;AAChC,cAAc,iBAAiB,OAAO,WAAW,qBAAqB;AACtE,SAAS,sBAAsB;AAC/B,cAAc,UAAU,iBAAiB;AACzC,SAAS,6BAA6B;AACtC,cACE,eACA,mBACA,0BACA,yBACA,2BACA,4BACK;AACP,SAAS,gCAAgC;AACzC,cAAc,2BAA2B;AACzC,SAAS,sBAAsB;AAC/B,cAAc,UAAU,iBAAiB;AACzC,cAAc,mBAAmB;AACjC,SAAS,oBAAoB;AAC7B,cAAc,QAAQ,eAAe","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Flavored } from "@palantir/pack.core";
|
|
2
|
+
import type { Model, ModelData } from "./Model.js";
|
|
3
|
+
import type { UserId } from "./UserRef.js";
|
|
4
|
+
export type ActivityEventId = Flavored<"pack:EventId">;
|
|
5
|
+
export declare const ActivityEventDataType: {
|
|
6
|
+
readonly CUSTOM_EVENT: "customEvent";
|
|
7
|
+
readonly UNKNOWN: "unknown";
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Application specific custom activity event data, as described in a transaction edit,
|
|
11
|
+
* using an application sdk's generated model types.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const unsubscribe = docRef.onActivity((docRef, event) => {
|
|
16
|
+
* console.log("Activity event:", event);
|
|
17
|
+
* });
|
|
18
|
+
* // Submit an edit with a description to generate an activity event.
|
|
19
|
+
* docRef.withTransaction(() => {
|
|
20
|
+
* // make some edits to the document here
|
|
21
|
+
* }, {
|
|
22
|
+
* model: MyEventModel,
|
|
23
|
+
* data: {
|
|
24
|
+
* myDataField: "some value",
|
|
25
|
+
* foo: 42,
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export interface ActivityEventDataCustom<M extends Model = Model> {
|
|
31
|
+
readonly type: typeof ActivityEventDataType.CUSTOM_EVENT;
|
|
32
|
+
readonly model: M;
|
|
33
|
+
readonly eventData: ModelData<M>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Fallback for unrecognized activity event types.
|
|
37
|
+
*
|
|
38
|
+
* This allows some flexibility with new event types added to the platform.
|
|
39
|
+
* Likely unknown events represent a new platform event type and will be handled
|
|
40
|
+
* in a future release of pack libraries and can be safely ignored by
|
|
41
|
+
* applications.
|
|
42
|
+
*/
|
|
43
|
+
export interface ActivityEventDataUnknown {
|
|
44
|
+
readonly type: "unknown";
|
|
45
|
+
readonly rawType: string;
|
|
46
|
+
readonly rawData: unknown;
|
|
47
|
+
}
|
|
48
|
+
export type ActivityEventData = ActivityEventDataCustom | ActivityEventDataUnknown;
|
|
49
|
+
/**
|
|
50
|
+
* An event representing an activity that has occurred on a document. This
|
|
51
|
+
* includes standard document events as well as custom application-specific
|
|
52
|
+
* events describing document edits.
|
|
53
|
+
*
|
|
54
|
+
* ActivityEvents are useful for building activity feeds, or notifications.
|
|
55
|
+
*/
|
|
56
|
+
export interface ActivityEvent {
|
|
57
|
+
/** Multiple events with the same aggregationKey may be collapsed. */
|
|
58
|
+
readonly aggregationKey: string;
|
|
59
|
+
readonly createdBy: UserId;
|
|
60
|
+
readonly createdInstant: number;
|
|
61
|
+
readonly eventData: ActivityEventData;
|
|
62
|
+
readonly eventId: ActivityEventId;
|
|
63
|
+
readonly isRead: boolean;
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,gBAAgB;AAC9B,cAAc,OAAO,iBAAiB;AACtC,cAAc,cAAc;AAE5B,YAAY,kBAAkB,SAAS;AAEvC,OAAO,cAAM;UACX,cAAc;UACd,SAAS;;;;;;;;;;;;;;;;;;;;;;;AAwBX,iBAAiB,wBAAwB,UAAU,QAAQ,OAAO;UACvD,aAAa,sBAAsB;UACnC,OAAO;UACP,WAAW,UAAU;;;;;;;;;;AAahC,iBAAiB,yBAAyB;UAC/B,MAAM;UACN;UACA;;AAGX,YAAY,oBAAoB,0BAA0B;;;;;;;;AAS1D,iBAAiB,cAAc;;UAEpB;UACA,WAAW;UACX;UACA,WAAW;UACX,SAAS;UACT","names":[],"sources":["../../../src/types/ActivityEvent.ts"],"version":3,"file":"ActivityEvent.d.ts"}
|
|
@@ -1,17 +1,211 @@
|
|
|
1
1
|
import type { Flavored } from "@palantir/pack.core";
|
|
2
|
+
import type { ActivityEvent } from "./ActivityEvent.js";
|
|
2
3
|
import type { DocumentMetadata } from "./DocumentMetadata.js";
|
|
3
4
|
import type { DocumentSchema, DocumentState } from "./DocumentSchema.js";
|
|
4
|
-
import type { Model } from "./Model.js";
|
|
5
|
+
import type { EditDescription, Model, ModelData } from "./Model.js";
|
|
6
|
+
import type { PresenceEvent } from "./PresenceEvent.js";
|
|
5
7
|
import type { RecordCollectionRef } from "./RecordCollectionRef.js";
|
|
6
8
|
import type { Unsubscribe } from "./Unsubscribe.js";
|
|
7
9
|
export type DocumentId = Flavored<"DocumentId">;
|
|
10
|
+
/**
|
|
11
|
+
* Options for subscribing to presence events on a document.
|
|
12
|
+
*/
|
|
13
|
+
export interface PresenceSubscriptionOptions {
|
|
14
|
+
/**
|
|
15
|
+
* If true, presence events originating from the local user will be ignored.
|
|
16
|
+
*
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
readonly ignoreSelfUpdates?: boolean;
|
|
20
|
+
}
|
|
8
21
|
export declare const DocumentRefBrand: unique symbol;
|
|
22
|
+
/**
|
|
23
|
+
* A reference to a document in the Pack system.
|
|
24
|
+
*
|
|
25
|
+
* A documentRef returned by various interfaces from the pack app instance or
|
|
26
|
+
* utilities such as react hooks from @palantir/pack.state.react provides
|
|
27
|
+
* methods to interact with the document, such as subscribing to & making
|
|
28
|
+
* changes to the document state and also related activity or presence events.
|
|
29
|
+
*
|
|
30
|
+
* A stable documentRef object is guaranteed for the same document id within the
|
|
31
|
+
* same app instance.
|
|
32
|
+
*/
|
|
9
33
|
export interface DocumentRef<D extends DocumentSchema = DocumentSchema> {
|
|
10
34
|
readonly id: DocumentId;
|
|
11
35
|
readonly schema: D;
|
|
12
36
|
readonly [DocumentRefBrand]: typeof DocumentRefBrand;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Get a snapshot of the current document state.
|
|
39
|
+
*
|
|
40
|
+
* This is largely for debugging and dumps a json view of the whole document state.
|
|
41
|
+
*
|
|
42
|
+
* @experimental
|
|
43
|
+
*/
|
|
44
|
+
getDocSnapshot(): Promise<DocumentState<D>>;
|
|
45
|
+
/**
|
|
46
|
+
* Get or create a ref to the collection of all records for the specified
|
|
47
|
+
* model in this document.
|
|
48
|
+
*
|
|
49
|
+
* @param model The model type from the application's generated schema.
|
|
50
|
+
* @returns A stable {@link RecordCollectionRef} object providing an interface
|
|
51
|
+
* to interact with the records of the specified model type in this document.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { DocumentModel, MyModel } from "@myapp/schema";
|
|
56
|
+
* import { app } from "./appInstance";
|
|
57
|
+
*
|
|
58
|
+
* const docRef = app.state.createDocRef(DocumentModel, someDocumentId);
|
|
59
|
+
* const myRecordCollection = docRef.getRecords(MyModel);
|
|
60
|
+
*
|
|
61
|
+
* myRecordCollection.onItemsAdded((items) => {
|
|
62
|
+
* console.log("New records added:", items);
|
|
63
|
+
* })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
getRecords<R extends Model>(model: R): RecordCollectionRef<R>;
|
|
67
|
+
/**
|
|
68
|
+
* Subscribe to activity events for the document.
|
|
69
|
+
*
|
|
70
|
+
* Activity is used by applications to describe changes to the document, for
|
|
71
|
+
* populating activity feeds, change histories, notifications and similar
|
|
72
|
+
* features.
|
|
73
|
+
*
|
|
74
|
+
* @see {withTransaction} for making edits that generate activity events.
|
|
75
|
+
*
|
|
76
|
+
* @returns An unsubscribe function.
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const unsubscribe = docRef.onActivity((docRef, event) => {
|
|
80
|
+
* console.log("Activity event:", event);
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // Submit an edit with a description to generate an activity event.
|
|
84
|
+
* docRef.withTransaction(() => {
|
|
85
|
+
* // make some edits to the document here
|
|
86
|
+
* }, {
|
|
87
|
+
* model: MyEventModel,
|
|
88
|
+
* data: {
|
|
89
|
+
* myDataField: "some value",
|
|
90
|
+
* foo: 42,
|
|
91
|
+
* },
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* // Later, to unsubscribe:
|
|
95
|
+
* unsubscribe();
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
onActivity(callback: (docRef: DocumentRef<D>, event: ActivityEvent) => void): Unsubscribe;
|
|
99
|
+
/**
|
|
100
|
+
* Subscribe to metadata changes for the document.
|
|
101
|
+
*
|
|
102
|
+
* @returns An unsubscribe function.
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const unsubscribe = docRef.onMetadataChange((docRef, metadata) => {
|
|
106
|
+
* console.log("Metadata changed:", metadata);
|
|
107
|
+
* });
|
|
108
|
+
*
|
|
109
|
+
* // Later, to unsubscribe:
|
|
110
|
+
* unsubscribe();
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
onMetadataChange(callback: (docRef: DocumentRef<D>, metadata: DocumentMetadata) => void): Unsubscribe;
|
|
114
|
+
/**
|
|
115
|
+
* Subscribe to presence events for the document.
|
|
116
|
+
*
|
|
117
|
+
* Presence events are a way to broadcast and receive non-persisted awareness
|
|
118
|
+
* and presence events. For example, a user moving their cursor in a
|
|
119
|
+
* collaborative editor could be broadcast via custom presence events.
|
|
120
|
+
*
|
|
121
|
+
* @see {@link updateCustomPresence} to publish custom presence updates.
|
|
122
|
+
*
|
|
123
|
+
* @param callback The callback to invoke on presence events.
|
|
124
|
+
* @param options Options for the presence subscription.
|
|
125
|
+
* @returns An unsubscribe function.
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* const unsubscribe = docRef.onPresence((docRef, event) => {
|
|
129
|
+
* console.log("Presence event:", event);
|
|
130
|
+
* if (event.model === MyPresenceModel) {
|
|
131
|
+
* updateCursor((event.eventData as ModelData<MyPresenceModel>).cursorPosition);
|
|
132
|
+
* }
|
|
133
|
+
* }, { ignoreSelfUpdates: true });
|
|
134
|
+
*
|
|
135
|
+
* // Broadcast a presence update
|
|
136
|
+
* docRef.updateCustomPresence(MyPresenceModel, {
|
|
137
|
+
* cursorPosition: [42, 7],
|
|
138
|
+
* });
|
|
139
|
+
*
|
|
140
|
+
* // Later, to unsubscribe:
|
|
141
|
+
* unsubscribe();
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
onPresence(callback: (docRef: DocumentRef<D>, event: PresenceEvent) => void, options?: PresenceSubscriptionOptions): Unsubscribe;
|
|
145
|
+
/**
|
|
146
|
+
* Subscribe to be notified any time the document state changes.
|
|
147
|
+
* This is largely for testing purposes.
|
|
148
|
+
*
|
|
149
|
+
* @experimental
|
|
150
|
+
*
|
|
151
|
+
* @param callback The callback to invoke on state changes.
|
|
152
|
+
* @returns An unsubscribe function.
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* const unsubscribe = docRef.onStateChange((docRef) => {
|
|
156
|
+
* console.log("Document state changed:", docRef);
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* // Later, to unsubscribe:
|
|
160
|
+
* unsubscribe();
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
onStateChange(callback: (docRef: DocumentRef<D>) => void): Unsubscribe;
|
|
164
|
+
/**
|
|
165
|
+
* Broadcasts an update for the specified model as presence data to other
|
|
166
|
+
* subscribers.
|
|
167
|
+
*
|
|
168
|
+
* Presence data is ephemeral and not stored as part of the document state. It
|
|
169
|
+
* is intended for broadcasting transient user presence and awareness
|
|
170
|
+
* information. Each different model type used for presence is expected to
|
|
171
|
+
* update the latest 'presence state' for that model type.
|
|
172
|
+
*
|
|
173
|
+
* @see {@link onPresence} to subscribe to presence updates.
|
|
174
|
+
*
|
|
175
|
+
* @param model The model type to update presence for.
|
|
176
|
+
* @param eventData The new presence data for the model.
|
|
177
|
+
*/
|
|
178
|
+
updateCustomPresence<M extends Model = Model>(model: M, eventData: ModelData<M>): void;
|
|
179
|
+
/**
|
|
180
|
+
* Execute one or more document edits within a transaction, optionally providing
|
|
181
|
+
* a description of the edit for activity tracking.
|
|
182
|
+
*
|
|
183
|
+
* All edits made within the provided function will be treated as a single
|
|
184
|
+
* atomic edit operation. If a description is provided, an activity event will
|
|
185
|
+
* be generated for the edit.
|
|
186
|
+
*
|
|
187
|
+
* If this is called within an existing transaction, the inner edits will be
|
|
188
|
+
* included in the outer transaction only, and the inner descriptions will be
|
|
189
|
+
* discarded.
|
|
190
|
+
*
|
|
191
|
+
* @see {@link onActivity} to subscribe to activity events on this document.
|
|
192
|
+
*
|
|
193
|
+
* @param fn A lambda including some document edits.
|
|
194
|
+
* @param description Optional description of the edit for activity tracking.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* docRef.withTransaction(() => {
|
|
199
|
+
* const myRecords = docRef.getRecords(MyModel);
|
|
200
|
+
* myRecords.set("record-1", { field: "new value" });
|
|
201
|
+
* myRecords.delete("record-2");
|
|
202
|
+
* }, {
|
|
203
|
+
* model: MyEditEventModel,
|
|
204
|
+
* data: {
|
|
205
|
+
* summary: "Updated record-1 and deleted record-2",
|
|
206
|
+
* },
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
withTransaction(fn: () => void, description?: EditDescription): void;
|
|
17
211
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cAAc,gBAAgB;AAC9B,cAAc,wBAAwB;AACtC,cAAc,gBAAgB,qBAAqB;AACnD,cAAc,
|
|
1
|
+
{"mappings":"AAgBA,cAAc,gBAAgB;AAC9B,cAAc,qBAAqB;AACnC,cAAc,wBAAwB;AACtC,cAAc,gBAAgB,qBAAqB;AACnD,cAAc,iBAAiB,OAAO,iBAAiB;AACvD,cAAc,qBAAqB;AACnC,cAAc,2BAA2B;AACzC,cAAc,mBAAmB;AAEjC,YAAY,aAAa,SAAS;;;;AAKlC,iBAAiB,4BAA4B;;;;;;UAMlC;;AAGX,OAAO,cAAMA;;;;;;;;;;;;AAab,iBAAiB,YAAY,UAAU,iBAAiB,gBAAgB;UAC7D,IAAI;UACJ,QAAQ;WACP,0BAA0B;;;;;;;;CASpC,kBAAkB,QAAQ,cAAc;;;;;;;;;;;;;;;;;;;;;;CAuBxC,WAAW,UAAU,OAAO,OAAO,IAAI,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiC3D,WACE,WAAW,QAAQ,YAAY,IAAI,OAAO,yBACzC;;;;;;;;;;;;;;;CAgBH,iBACE,WAAW,QAAQ,YAAY,IAAI,UAAU,4BAC5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCH,WACE,WAAW,QAAQ,YAAY,IAAI,OAAO,wBAC1C,UAAU,8BACT;;;;;;;;;;;;;;;;;;;CAoBH,cACE,WAAW,QAAQ,YAAY,cAC9B;;;;;;;;;;;;;;;CAgBH,qBAAqB,UAAU,QAAQ,OACrC,OAAO,GACP,WAAW,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCvB,gBAAgB,gBAAgB,cAAc","names":["DocumentRefBrand: unique symbol"],"sources":["../../../src/types/DocumentRef.ts"],"version":3,"file":"DocumentRef.d.ts"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { WithMetadata } from "./Metadata.js";
|
|
2
2
|
import type { Model, ModelData } from "./Model.js";
|
|
3
|
+
/**
|
|
4
|
+
* The base type for an application sdk's generated document schema.
|
|
5
|
+
*/
|
|
3
6
|
export interface DocumentSchema extends WithMetadata<DocumentSchemaMetadata> {
|
|
4
7
|
readonly [modelName: string]: Model;
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* The plain object representation of the state of a document.
|
|
11
|
+
*/
|
|
6
12
|
export type DocumentState<S extends DocumentSchema> = { readonly [K in Exclude<keyof S, symbol>] : {
|
|
7
13
|
readonly [key: string]: ModelData<S[K]>;
|
|
8
14
|
} };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cAAc,oBAAoB;AAClC,cAAc,OAAO,iBAAiB
|
|
1
|
+
{"mappings":"AAgBA,cAAc,oBAAoB;AAClC,cAAc,OAAO,iBAAiB;;;;AAKtC,iBAAiB,uBAAuB,aAAa,wBAAwB;+BAC7C;;;;;AAMhC,YAAY,cAAc,UAAU,8BACxB,KAAK,cAAc,cAAa;yBAA0B,UAAU,EAAE;;AAGlF,iBAAiB,uBAAuB;UAC7B","names":[],"sources":["../../../src/types/DocumentSchema.ts"],"version":3,"file":"DocumentSchema.d.ts"}
|
|
@@ -13,6 +13,13 @@ export interface Model<
|
|
|
13
13
|
readonly zodSchema: Readonly<Z>;
|
|
14
14
|
}
|
|
15
15
|
export type ModelData<M extends Model> = M["__type"];
|
|
16
|
+
/**
|
|
17
|
+
* Describes an edit made to a document.
|
|
18
|
+
*/
|
|
19
|
+
export interface EditDescription<M extends Model = Model> {
|
|
20
|
+
readonly data: ModelData<M>;
|
|
21
|
+
readonly model: M;
|
|
22
|
+
}
|
|
16
23
|
export declare const ExternalRefType: {
|
|
17
24
|
readonly DOC_REF: "docRef";
|
|
18
25
|
readonly MEDIA_REF: "mediaRef";
|
|
@@ -21,6 +28,12 @@ export declare const ExternalRefType: {
|
|
|
21
28
|
};
|
|
22
29
|
export type ExternalRefType = typeof ExternalRefType[keyof typeof ExternalRefType];
|
|
23
30
|
export interface ModelMetadata<T = unknown> {
|
|
31
|
+
/**
|
|
32
|
+
* Which fields in the model are external references (e.g. UserRef, DocumentRef, etc).
|
|
33
|
+
*/
|
|
24
34
|
readonly externalRefFieldTypes?: Readonly<Record<keyof T, ExternalRefType>>;
|
|
35
|
+
/**
|
|
36
|
+
* The name of the model (should match the typescript symbol).
|
|
37
|
+
*/
|
|
25
38
|
readonly name: string;
|
|
26
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cAAc,eAAe;AAC7B,cAAc,oBAAoB;;;;;;AAQlC,iBAAiB;CAAM;CAAa,UAAU,QAAQ,KAAK,QAAQ;UACzD,aAAa,cAAc,IACrC;UACW,QAAQ;UACR,WAAW,SAAS;;AAG/B,YAAY,UAAU,UAAU,SAAS,EAAE;
|
|
1
|
+
{"mappings":"AAgBA,cAAc,eAAe;AAC7B,cAAc,oBAAoB;;;;;;AAQlC,iBAAiB;CAAM;CAAa,UAAU,QAAQ,KAAK,QAAQ;UACzD,aAAa,cAAc,IACrC;UACW,QAAQ;UACR,WAAW,SAAS;;AAG/B,YAAY,UAAU,UAAU,SAAS,EAAE;;;;AAK3C,iBAAiB,gBAAgB,UAAU,QAAQ,OAAO;UAC/C,MAAM,UAAU;UAChB,OAAO;;AAGlB,OAAO,cAAM;UACX,SAAS;UACT,WAAW;UACX,YAAY;UACZ,UAAU;;AAGZ,YAAY,yBAAyB,6BAA6B;AAElE,iBAAiB,cAAc,aAAa;;;;UAIjC,wBAAwB,SAAS,aAAa,GAAG;;;;UAIjD","names":[],"sources":["../../../src/types/Model.ts"],"version":3,"file":"Model.d.ts"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Model, ModelData } from "./Model.js";
|
|
2
|
+
import type { UserId } from "./UserRef.js";
|
|
3
|
+
export declare const PresenceEventDataType: {
|
|
4
|
+
readonly ARRIVED: "presenceArrived";
|
|
5
|
+
readonly DEPARTED: "presenceDeparted";
|
|
6
|
+
readonly CUSTOM_EVENT: "customEvent";
|
|
7
|
+
readonly UNKNOWN: "unknown";
|
|
8
|
+
};
|
|
9
|
+
export type PresenceEventDataType = typeof PresenceEventDataType[keyof typeof PresenceEventDataType];
|
|
10
|
+
/**
|
|
11
|
+
* Any client that subscribes to presence events via `DocumentRef.onPresence` will
|
|
12
|
+
* be considered 'present' on the document, and trigger an 'arrived' presence event.
|
|
13
|
+
* When they disconnect or unsubscribe from presence events, a 'departed' presence event
|
|
14
|
+
* will be triggered.
|
|
15
|
+
*/
|
|
16
|
+
export interface PresenceEventDataArrived {
|
|
17
|
+
readonly type: typeof PresenceEventDataType.ARRIVED;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Any client that subscribes to presence events via `DocumentRef.onPresence` will
|
|
21
|
+
* be considered 'present' on the document, and trigger an 'arrived' presence event.
|
|
22
|
+
* When they disconnect or unsubscribe from presence events, a 'departed' presence event
|
|
23
|
+
* will be triggered.
|
|
24
|
+
*/
|
|
25
|
+
export interface PresenceEventDataDeparted {
|
|
26
|
+
readonly type: typeof PresenceEventDataType.DEPARTED;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Application specific custom presence event data.
|
|
30
|
+
*
|
|
31
|
+
* Each different model type used for presence is expected to update the latest
|
|
32
|
+
* 'presence state' for that model type.
|
|
33
|
+
*
|
|
34
|
+
* For example, your app may have need to broadcast user cursor positions and
|
|
35
|
+
* selection ranges as presence data. You could define your schema to include a
|
|
36
|
+
* `CursorPosition` and `SelectionRange` record types, and set them
|
|
37
|
+
* independently via `{@link DocumentRef.updateCustomPresence}`. Each model type
|
|
38
|
+
* sent as a custom presence event should be considered a separate 'channel' of
|
|
39
|
+
* presence data on this document.
|
|
40
|
+
*/
|
|
41
|
+
export interface PresenceEventDataCustom<M extends Model = Model> {
|
|
42
|
+
readonly type: typeof PresenceEventDataType.CUSTOM_EVENT;
|
|
43
|
+
readonly eventData: ModelData<M>;
|
|
44
|
+
readonly model: M;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Fallback for unrecognized activity event types.
|
|
48
|
+
*
|
|
49
|
+
* This allows some flexibility with new event types added to the platform.
|
|
50
|
+
* Likely unknown events represent a new platform event type and will be handled
|
|
51
|
+
* in a future release of pack libraries and can be safely ignored by
|
|
52
|
+
* applications.
|
|
53
|
+
*/
|
|
54
|
+
export interface PresenceEventUnknown {
|
|
55
|
+
readonly type: "unknown";
|
|
56
|
+
readonly rawType: string;
|
|
57
|
+
readonly rawData: unknown;
|
|
58
|
+
}
|
|
59
|
+
export type PresenceEventData = PresenceEventDataArrived | PresenceEventDataDeparted | PresenceEventDataCustom | PresenceEventUnknown;
|
|
60
|
+
/**
|
|
61
|
+
* An event representing a transient awareness or presence change for a user on this document.
|
|
62
|
+
* The presence channel is intended for ephemeral data such as user cursors, selections, or
|
|
63
|
+
* other live collaboration indicators.
|
|
64
|
+
*
|
|
65
|
+
* PresenceEvents are not persisted in document history.
|
|
66
|
+
*
|
|
67
|
+
* When a client goes offline, its presence is considered departed and any presence events
|
|
68
|
+
* associated with that user should be considered stale and / or cleared.
|
|
69
|
+
*/
|
|
70
|
+
export interface PresenceEvent {
|
|
71
|
+
readonly userId: UserId;
|
|
72
|
+
readonly eventData: PresenceEventData;
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,OAAO,iBAAiB;AACtC,cAAc,cAAc;AAE5B,OAAO,cAAM;UACX,SAAS;UACT,UAAU;UACV,cAAc;UACd,SAAS;;AAGX,YAAY,+BACH,mCAAmC;;;;;;;AAQ5C,iBAAiB,yBAAyB;UAC/B,aAAa,sBAAsB;;;;;;;;AAS9C,iBAAiB,0BAA0B;UAChC,aAAa,sBAAsB;;;;;;;;;;;;;;;AAgB9C,iBAAiB,wBAAwB,UAAU,QAAQ,OAAO;UACvD,aAAa,sBAAsB;UACnC,WAAW,UAAU;UACrB,OAAO;;;;;;;;;;AAWlB,iBAAiB,qBAAqB;UAC3B,MAAM;UACN;UACA;;AAGX,YAAY,oBACR,2BACA,4BACA,0BACA;;;;;;;;;;;AAYJ,iBAAiB,cAAc;UACpB,QAAQ;UACR,WAAW","names":[],"sources":["../../../src/types/PresenceEvent.ts"],"version":3,"file":"PresenceEvent.d.ts"}
|
|
@@ -2,17 +2,71 @@ import type { DocumentRef } from "./DocumentRef.js";
|
|
|
2
2
|
import type { Model, ModelData } from "./Model.js";
|
|
3
3
|
import type { RecordId, RecordRef } from "./RecordRef.js";
|
|
4
4
|
export declare const RecordCollectionRefBrand: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* A reference providing an API to interact with a collection of records in a document.
|
|
7
|
+
*/
|
|
5
8
|
export interface RecordCollectionRef<M extends Model = Model> {
|
|
6
9
|
readonly docRef: DocumentRef;
|
|
7
10
|
readonly model: M;
|
|
8
11
|
readonly [RecordCollectionRefBrand]: typeof RecordCollectionRefBrand;
|
|
12
|
+
/**
|
|
13
|
+
* Delete a record from the collection (and the document).
|
|
14
|
+
*
|
|
15
|
+
* @param id - The ID of the record to delete.
|
|
16
|
+
* @returns A promise that resolves when the record is deleted.
|
|
17
|
+
*/
|
|
9
18
|
delete(id: RecordId): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Get a {@link RecordRef} from the collection. This provides the main API for
|
|
21
|
+
* accessing and updating individual records in a document.
|
|
22
|
+
*
|
|
23
|
+
* @param id - The ID of the record to get.
|
|
24
|
+
* @returns The record reference, or undefined if it doesn't exist. The
|
|
25
|
+
* recordRef is a stable object and can be used for reference equality checks.
|
|
26
|
+
*/
|
|
10
27
|
get(id: RecordId): RecordRef<M> | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Check if a record exists in the collection.
|
|
30
|
+
*
|
|
31
|
+
* @param id - The ID of the record to check.
|
|
32
|
+
* @returns True if the record exists, false otherwise.
|
|
33
|
+
*/
|
|
11
34
|
has(id: RecordId): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Set the data for a record in the collection (creating it if it doesn't exist).
|
|
37
|
+
*
|
|
38
|
+
* @param id - The ID of the record to set.
|
|
39
|
+
* @param state - The data to set for the record.
|
|
40
|
+
* @returns A promise that resolves when the record is set.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const recordCollection = docRef.getRecords(MyModel);
|
|
45
|
+
* await recordCollection.set("record-id", { field: "value" });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
12
48
|
set(id: RecordId, state: ModelData<M>): Promise<void>;
|
|
13
49
|
readonly size: number;
|
|
14
50
|
[Symbol.iterator](): Iterator<RecordRef<M>>;
|
|
51
|
+
/**
|
|
52
|
+
* Subscribe to added items in the collection.
|
|
53
|
+
*
|
|
54
|
+
* @param callback - The callback to invoke when items are added.
|
|
55
|
+
* @returns An unsubscribe function.
|
|
56
|
+
*/
|
|
15
57
|
readonly onItemsAdded: (callback: (items: readonly RecordRef<M>[]) => void) => () => void;
|
|
58
|
+
/**
|
|
59
|
+
* Subscribe to changed items in the collection.
|
|
60
|
+
*
|
|
61
|
+
* @param callback - The callback to invoke when items are changed.
|
|
62
|
+
* @returns An unsubscribe function.
|
|
63
|
+
*/
|
|
16
64
|
readonly onItemsChanged: (callback: (items: readonly RecordRef<M>[]) => void) => () => void;
|
|
65
|
+
/**
|
|
66
|
+
* Subscribe to deleted items in the collection.
|
|
67
|
+
*
|
|
68
|
+
* @param callback - The callback to invoke when items are deleted.
|
|
69
|
+
* @returns An unsubscribe function.
|
|
70
|
+
*/
|
|
17
71
|
readonly onItemsDeleted: (callback: (items: readonly RecordRef<M>[]) => void) => () => void;
|
|
18
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cAAc,mBAAmB;AACjC,cAAc,OAAO,iBAAiB;AACtC,cAAc,UAAU,iBAAiB;AAEzC,OAAO,cAAMA
|
|
1
|
+
{"mappings":"AAgBA,cAAc,mBAAmB;AACjC,cAAc,OAAO,iBAAiB;AACtC,cAAc,UAAU,iBAAiB;AAEzC,OAAO,cAAMA;;;;AAOb,iBAAiB,oBAAoB,UAAU,QAAQ,OAAO;UACnD,QAAQ;UACR,OAAO;WACN,kCAAkC;;;;;;;CAQ5C,OAAO,IAAI,WAAW;;;;;;;;;CAStB,IAAI,IAAI,WAAW,UAAU;;;;;;;CAO7B,IAAI,IAAI;;;;;;;;;;;;;;CAcR,IAAI,IAAI,UAAU,OAAO,UAAU,KAAK;UAC/B;EAER,OAAO,aAAa,SAAS,UAAU;;;;;;;UAQ/B,eACP,WAAW,gBAAgB,UAAU;;;;;;;UAS9B,iBACP,WAAW,gBAAgB,UAAU;;;;;;;UAS9B,iBACP,WAAW,gBAAgB,UAAU","names":["RecordCollectionRefBrand: unique symbol"],"sources":["../../../src/types/RecordCollectionRef.ts"],"version":3,"file":"RecordCollectionRef.d.ts"}
|