@osdk/client 2.2.0-beta.3 → 2.2.0-beta.4

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/browser/Logger.js.map +1 -1
  3. package/build/browser/observable/ObservableClient.js.map +1 -1
  4. package/build/browser/observable/internal/ActionApplication.js +102 -0
  5. package/build/browser/observable/internal/ActionApplication.js.map +1 -0
  6. package/build/browser/observable/internal/CacheKey.js +38 -1
  7. package/build/browser/observable/internal/CacheKey.js.map +1 -1
  8. package/build/browser/observable/internal/CacheKeys.js +4 -4
  9. package/build/browser/observable/internal/CacheKeys.js.map +1 -1
  10. package/build/browser/observable/internal/ChangedObjects.js +24 -1
  11. package/build/browser/observable/internal/ChangedObjects.js.map +1 -1
  12. package/build/browser/observable/internal/Layer.js +3 -3
  13. package/build/browser/observable/internal/Layer.js.map +1 -1
  14. package/build/browser/observable/internal/ListQuery.js +188 -66
  15. package/build/browser/observable/internal/ListQuery.js.map +1 -1
  16. package/build/browser/observable/internal/ObjectQuery.js +16 -3
  17. package/build/browser/observable/internal/ObjectQuery.js.map +1 -1
  18. package/build/browser/observable/internal/ObservableClientImpl.js +2 -2
  19. package/build/browser/observable/internal/ObservableClientImpl.js.map +1 -1
  20. package/build/browser/observable/internal/OptimisticJob.js +30 -29
  21. package/build/browser/observable/internal/OptimisticJob.js.map +1 -1
  22. package/build/browser/observable/internal/Query.js +42 -2
  23. package/build/browser/observable/internal/Query.js.map +1 -1
  24. package/build/browser/observable/internal/Store.js +259 -126
  25. package/build/browser/observable/internal/Store.js.map +1 -1
  26. package/build/browser/observable/internal/Store.test.js +416 -76
  27. package/build/browser/observable/internal/Store.test.js.map +1 -1
  28. package/build/browser/observable/internal/testUtils.js +142 -6
  29. package/build/browser/observable/internal/testUtils.js.map +1 -1
  30. package/build/browser/util/UserAgent.js +1 -1
  31. package/build/cjs/index.cjs +1 -1
  32. package/build/cjs/public/unstable-do-not-use.cjs +657 -268
  33. package/build/cjs/public/unstable-do-not-use.cjs.map +1 -1
  34. package/build/cjs/public/unstable-do-not-use.d.cts +13 -4
  35. package/build/esm/Logger.js.map +1 -1
  36. package/build/esm/observable/ObservableClient.js.map +1 -1
  37. package/build/esm/observable/internal/ActionApplication.js +102 -0
  38. package/build/esm/observable/internal/ActionApplication.js.map +1 -0
  39. package/build/esm/observable/internal/CacheKey.js +38 -1
  40. package/build/esm/observable/internal/CacheKey.js.map +1 -1
  41. package/build/esm/observable/internal/CacheKeys.js +4 -4
  42. package/build/esm/observable/internal/CacheKeys.js.map +1 -1
  43. package/build/esm/observable/internal/ChangedObjects.js +24 -1
  44. package/build/esm/observable/internal/ChangedObjects.js.map +1 -1
  45. package/build/esm/observable/internal/Layer.js +3 -3
  46. package/build/esm/observable/internal/Layer.js.map +1 -1
  47. package/build/esm/observable/internal/ListQuery.js +188 -66
  48. package/build/esm/observable/internal/ListQuery.js.map +1 -1
  49. package/build/esm/observable/internal/ObjectQuery.js +16 -3
  50. package/build/esm/observable/internal/ObjectQuery.js.map +1 -1
  51. package/build/esm/observable/internal/ObservableClientImpl.js +2 -2
  52. package/build/esm/observable/internal/ObservableClientImpl.js.map +1 -1
  53. package/build/esm/observable/internal/OptimisticJob.js +30 -29
  54. package/build/esm/observable/internal/OptimisticJob.js.map +1 -1
  55. package/build/esm/observable/internal/Query.js +42 -2
  56. package/build/esm/observable/internal/Query.js.map +1 -1
  57. package/build/esm/observable/internal/Store.js +259 -126
  58. package/build/esm/observable/internal/Store.js.map +1 -1
  59. package/build/esm/observable/internal/Store.test.js +416 -76
  60. package/build/esm/observable/internal/Store.test.js.map +1 -1
  61. package/build/esm/observable/internal/testUtils.js +142 -6
  62. package/build/esm/observable/internal/testUtils.js.map +1 -1
  63. package/build/esm/util/UserAgent.js +1 -1
  64. package/build/types/Logger.d.ts +1 -2
  65. package/build/types/Logger.d.ts.map +1 -1
  66. package/build/types/observable/ObservableClient.d.ts +10 -3
  67. package/build/types/observable/ObservableClient.d.ts.map +1 -1
  68. package/build/types/observable/internal/ActionApplication.d.ts +9 -0
  69. package/build/types/observable/internal/ActionApplication.d.ts.map +1 -0
  70. package/build/types/observable/internal/CacheKeys.d.ts +2 -1
  71. package/build/types/observable/internal/CacheKeys.d.ts.map +1 -1
  72. package/build/types/observable/internal/ChangedObjects.d.ts +6 -2
  73. package/build/types/observable/internal/ChangedObjects.d.ts.map +1 -1
  74. package/build/types/observable/internal/Layer.d.ts +1 -1
  75. package/build/types/observable/internal/Layer.d.ts.map +1 -1
  76. package/build/types/observable/internal/ListQuery.d.ts +18 -17
  77. package/build/types/observable/internal/ListQuery.d.ts.map +1 -1
  78. package/build/types/observable/internal/ObjectQuery.d.ts +3 -3
  79. package/build/types/observable/internal/ObjectQuery.d.ts.map +1 -1
  80. package/build/types/observable/internal/OptimisticJob.d.ts +2 -2
  81. package/build/types/observable/internal/OptimisticJob.d.ts.map +1 -1
  82. package/build/types/observable/internal/Query.d.ts +6 -5
  83. package/build/types/observable/internal/Query.d.ts.map +1 -1
  84. package/build/types/observable/internal/Store.d.ts +47 -19
  85. package/build/types/observable/internal/Store.d.ts.map +1 -1
  86. package/build/types/observable/internal/testUtils.d.ts +13 -3
  87. package/build/types/observable/internal/testUtils.d.ts.map +1 -1
  88. package/package.json +8 -7
@@ -1 +1 @@
1
- {"version":3,"file":"Logger.js","names":[],"sources":["Logger.ts"],"sourcesContent":["/*\n * Copyright 2024 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 interface Logger {\n trace: LogFn;\n debug: LogFn;\n fatal: LogFn;\n error: LogFn;\n warn: LogFn;\n info: LogFn;\n\n isLevelEnabled(level: string): boolean;\n\n child(\n bindings: Record<string, any>,\n options?: { level?: string; msgPrefix?: string },\n ): Logger;\n}\n\ninterface LogFn {\n (obj: unknown, msg?: string, ...args: any[]): void;\n (msg: string, ...args: any[]): void;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"Logger.js","names":[],"sources":["Logger.ts"],"sourcesContent":["/*\n * Copyright 2024 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 interface Logger {\n trace: LogFn;\n debug: LogFn;\n fatal: LogFn;\n error: LogFn;\n warn: LogFn;\n info: LogFn;\n\n isLevelEnabled(level: string): boolean;\n\n child(\n bindings: Record<string, any>,\n options?: { level?: string; msgPrefix?: string },\n ): Logger;\n}\n\nexport interface LogFn {\n (obj: unknown, msg?: string, ...args: any[]): void;\n (msg: string, ...args: any[]): void;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"ObservableClient.js","names":["ObservableClientImpl","Store","ObservableClient","createObservableClient","client"],"sources":["ObservableClient.ts"],"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 type {\n ActionDefinition,\n ObjectTypeDefinition,\n PrimaryKeyType,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ActionSignatureFromDef } from \"../actions/applyAction.js\";\nimport type { Client } from \"../Client.js\";\nimport type { Canonical } from \"./internal/Canonical.js\";\nimport { ObservableClientImpl } from \"./internal/ObservableClientImpl.js\";\nimport { Store } from \"./internal/Store.js\";\nimport type { ListPayload } from \"./ListPayload.js\";\nimport type { ObjectPayload } from \"./ObjectPayload.js\";\nimport type { OptimisticBuilder } from \"./OptimisticBuilder.js\";\nimport type { SubFn } from \"./types.js\";\n\nexport type Status = \"init\" | \"loading\" | \"loaded\" | \"error\";\n\nexport namespace ObservableClient {\n export interface ApplyActionOptions {\n optimisticUpdate?: (ctx: OptimisticBuilder) => void;\n }\n}\nexport interface QueryOptions {\n dedupeInterval?: number;\n}\n\nexport interface ObserveOptions {\n mode?: \"offline\" | \"force\";\n}\n\nexport interface ObserveObjectOptions<T extends ObjectTypeDefinition>\n extends ObserveOptions\n{\n select?: PropertyKeys<T>[];\n}\n\nexport interface ListQueryOptions extends QueryOptions {\n pageSize?: number;\n}\n\nexport interface ObservableClient {\n observeObject<T extends ObjectTypeDefinition>(\n apiName: T[\"apiName\"] | T,\n pk: PrimaryKeyType<T>,\n options: ObserveOptions,\n subFn: SubFn<ObjectPayload>,\n ): Unsubscribable;\n\n observeList<T extends ObjectTypeDefinition>(\n apiName: T[\"apiName\"] | T,\n where: WhereClause<T>,\n options: ObserveOptions & ListQueryOptions,\n subFn: SubFn<ListPayload>,\n ): Unsubscribable;\n\n applyAction: <Q extends ActionDefinition<any>>(\n action: Q,\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n opts?: ObservableClient.ApplyActionOptions,\n ) => Promise<unknown>;\n\n canonicalizeWhereClause: <T extends ObjectTypeDefinition>(\n where: WhereClause<T>,\n ) => Canonical<WhereClause<T>>;\n}\n\nexport function createObservableClient(client: Client): ObservableClient {\n return new ObservableClientImpl(new Store(client));\n}\n\nexport interface Unsubscribable {\n unsubscribe: () => void;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,SAASA,oBAAoB,QAAQ,oCAAoC;AACzE,SAASC,KAAK,QAAQ,qBAAqB;AAAC,WAQ3BC,gBAAgB;AAiDjC,OAAO,SAASC,sBAAsBA,CAACC,MAAc,EAAoB;EACvE,OAAO,IAAIJ,oBAAoB,CAAC,IAAIC,KAAK,CAACG,MAAM,CAAC,CAAC;AACpD","ignoreList":[]}
1
+ {"version":3,"file":"ObservableClient.js","names":["ObservableClientImpl","Store","ObservableClient","createObservableClient","client"],"sources":["ObservableClient.ts"],"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 type {\n ActionDefinition,\n ObjectTypeDefinition,\n PrimaryKeyType,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ActionSignatureFromDef } from \"../actions/applyAction.js\";\nimport type { Client } from \"../Client.js\";\nimport type { Canonical } from \"./internal/Canonical.js\";\nimport { ObservableClientImpl } from \"./internal/ObservableClientImpl.js\";\nimport { Store } from \"./internal/Store.js\";\nimport type { ListPayload } from \"./ListPayload.js\";\nimport type { ObjectPayload } from \"./ObjectPayload.js\";\nimport type { OptimisticBuilder } from \"./OptimisticBuilder.js\";\nimport type { SubFn } from \"./types.js\";\n\nexport type Status = \"init\" | \"loading\" | \"loaded\" | \"error\";\n\nexport namespace ObservableClient {\n export interface ApplyActionOptions {\n optimisticUpdate?: (ctx: OptimisticBuilder) => void;\n }\n}\n\nexport interface CommonObserveOptions {\n dedupeInterval?: number;\n}\n\nexport interface ObserveOptions {\n mode?: \"offline\" | \"force\";\n}\n\nexport interface ObserveObjectOptions<T extends ObjectTypeDefinition>\n extends ObserveOptions\n{\n select?: PropertyKeys<T>[];\n}\n\nexport type OrderBy<Q extends ObjectTypeDefinition> = {\n [K in PropertyKeys<Q>]?: \"asc\" | \"desc\" | undefined;\n};\n\nexport interface ObserveListOptions<Q extends ObjectTypeDefinition>\n extends CommonObserveOptions, ObserveOptions\n{\n objectType: Q[\"apiName\"] | Q;\n where?: WhereClause<Q>;\n pageSize?: number;\n orderBy?: OrderBy<Q>;\n invalidationMode?: \"in-place\" | \"wait\" | \"reset\";\n expectedLength?: number;\n streamUpdates?: boolean;\n}\n\nexport interface ObservableClient {\n observeObject<T extends ObjectTypeDefinition>(\n apiName: T[\"apiName\"] | T,\n pk: PrimaryKeyType<T>,\n options: ObserveOptions,\n subFn: SubFn<ObjectPayload>,\n ): Unsubscribable;\n\n observeList<T extends ObjectTypeDefinition>(\n options: ObserveListOptions<T>,\n subFn: SubFn<ListPayload>,\n ): Unsubscribable;\n\n applyAction: <Q extends ActionDefinition<any>>(\n action: Q,\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n opts?: ObservableClient.ApplyActionOptions,\n ) => Promise<unknown>;\n\n canonicalizeWhereClause: <T extends ObjectTypeDefinition>(\n where: WhereClause<T>,\n ) => Canonical<WhereClause<T>>;\n}\n\nexport function createObservableClient(client: Client): ObservableClient {\n return new ObservableClientImpl(new Store(client));\n}\n\nexport interface Unsubscribable {\n unsubscribe: () => void;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,SAASA,oBAAoB,QAAQ,oCAAoC;AACzE,SAASC,KAAK,QAAQ,qBAAqB;AAAC,WAQ3BC,gBAAgB;AA4DjC,OAAO,SAASC,sBAAsBA,CAACC,MAAc,EAAoB;EACvE,OAAO,IAAIJ,oBAAoB,CAAC,IAAIC,KAAK,CAACG,MAAM,CAAC,CAAC;AACpD","ignoreList":[]}
@@ -0,0 +1,102 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { delay } from "msw";
18
+ import { createChangedObjects } from "./ChangedObjects.js";
19
+ import { runOptimisticJob } from "./OptimisticJob.js";
20
+ const ACTION_DELAY = process.env.NODE_ENV === "production" ? 0 : 1000;
21
+ export class ActionApplication {
22
+ constructor(store) {
23
+ this.store = store;
24
+ }
25
+ applyAction = (action, args, {
26
+ optimisticUpdate
27
+ } = {}) => {
28
+ const removeOptimisticResult = runOptimisticJob(this.store, optimisticUpdate);
29
+ return (async () => {
30
+ try {
31
+ // The types for client get confused when we dynamically applyAction so we
32
+ // have to deal with the `any` here and force cast it to what it should be.
33
+ // TODO: Update the types so this doesn't happen!
34
+
35
+ const actionResults = await this.store.client(action).applyAction(args, {
36
+ $returnEdits: true
37
+ });
38
+ if (ACTION_DELAY > 0) {
39
+ // eslint-disable-next-line no-console
40
+ console.log("action done, pausing");
41
+ await delay(ACTION_DELAY);
42
+ // eslint-disable-next-line no-console
43
+ console.log("action done, pausing done");
44
+ }
45
+ await this.#invalidateActionEditResponse(actionResults);
46
+ return actionResults;
47
+ } finally {
48
+ if (process.env.NODE_ENV !== "production") {
49
+ this.store.logger?.debug("optimistic action complete; remove the results");
50
+ }
51
+ // make sure this happens even if the action fails
52
+ await removeOptimisticResult();
53
+ }
54
+ })();
55
+ };
56
+ #invalidateActionEditResponse = async value => {
57
+ const typesToInvalidate = new Set();
58
+ let changes;
59
+ if (value.type === "edits") {
60
+ const promisesToWait = [];
61
+ // TODO we need an backend update for deletes
62
+ for (const obj of value.modifiedObjects) {
63
+ promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
64
+ }
65
+ for (const obj of value.addedObjects) {
66
+ promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
67
+ typesToInvalidate.add(obj.objectType);
68
+ }
69
+ await Promise.all(promisesToWait);
70
+
71
+ // the action invocation just gives back object ids,
72
+ // so we don't want to build the changes object
73
+ // until we have up to date values.
74
+ changes = this.#changesFromActionEditResponse(value);
75
+
76
+ // updates `changes` in place
77
+ await this.store.maybeRevalidateLists(changes);
78
+ } else {
79
+ for (const apiName of value.editedObjectTypes) {
80
+ typesToInvalidate.add(apiName.toString());
81
+ await this.store.invalidateObjectType(apiName, changes);
82
+ }
83
+ }
84
+ return value;
85
+ };
86
+ #changesFromActionEditResponse = value => {
87
+ const changes = createChangedObjects();
88
+ for (const changeType of ["addedObjects", "modifiedObjects"]) {
89
+ for (const {
90
+ objectType,
91
+ primaryKey
92
+ } of value[changeType] ?? []) {
93
+ const obj = this.store.getObject(objectType, primaryKey);
94
+ if (obj) {
95
+ changes[changeType].set(objectType, obj);
96
+ }
97
+ }
98
+ }
99
+ return changes;
100
+ };
101
+ }
102
+ //# sourceMappingURL=ActionApplication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActionApplication.js","names":["delay","createChangedObjects","runOptimisticJob","ACTION_DELAY","process","env","NODE_ENV","ActionApplication","constructor","store","applyAction","action","args","optimisticUpdate","removeOptimisticResult","actionResults","client","$returnEdits","console","log","invalidateActionEditResponse","logger","debug","value","typesToInvalidate","Set","changes","type","promisesToWait","obj","modifiedObjects","push","invalidateObject","objectType","primaryKey","addedObjects","add","Promise","all","changesFromActionEditResponse","maybeRevalidateLists","apiName","editedObjectTypes","toString","invalidateObjectType","changeType","getObject","set"],"sources":["ActionApplication.ts"],"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 type { ActionDefinition, ActionEditResponse } from \"@osdk/api\";\nimport { delay } from \"msw\";\nimport type { ActionSignatureFromDef } from \"../../actions/applyAction.js\";\n\nimport { type Changes, createChangedObjects } from \"./ChangedObjects.js\";\nimport { runOptimisticJob } from \"./OptimisticJob.js\";\nimport type { Store } from \"./Store.js\";\n\nconst ACTION_DELAY = process.env.NODE_ENV === \"production\" ? 0 : 1000;\n\nexport class ActionApplication {\n constructor(private store: Store) {}\n\n applyAction: <Q extends ActionDefinition<any>>(\n action: Q,\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n opts?: Store.ApplyActionOptions,\n ) => Promise<unknown> = (action, args, { optimisticUpdate } = {}) => {\n const removeOptimisticResult = runOptimisticJob(\n this.store,\n optimisticUpdate,\n );\n return (async () => {\n try {\n // The types for client get confused when we dynamically applyAction so we\n // have to deal with the `any` here and force cast it to what it should be.\n // TODO: Update the types so this doesn't happen!\n\n const actionResults: ActionEditResponse = await this.store.client(\n action,\n ).applyAction(args as any, { $returnEdits: true });\n\n if (ACTION_DELAY > 0) {\n // eslint-disable-next-line no-console\n console.log(\"action done, pausing\");\n await delay(ACTION_DELAY);\n // eslint-disable-next-line no-console\n console.log(\"action done, pausing done\");\n }\n await this.#invalidateActionEditResponse(actionResults);\n return actionResults;\n } finally {\n if (process.env.NODE_ENV !== \"production\") {\n this.store.logger?.debug(\n \"optimistic action complete; remove the results\",\n );\n }\n // make sure this happens even if the action fails\n await removeOptimisticResult();\n }\n })();\n };\n\n #invalidateActionEditResponse = async (\n value: ActionEditResponse,\n ): Promise<ActionEditResponse> => {\n const typesToInvalidate = new Set<string>();\n\n let changes: Changes | undefined;\n if (value.type === \"edits\") {\n const promisesToWait: Promise<any>[] = [];\n // TODO we need an backend update for deletes\n for (const obj of value.modifiedObjects) {\n promisesToWait.push(\n this.store.invalidateObject(obj.objectType, obj.primaryKey),\n );\n }\n\n for (const obj of value.addedObjects) {\n promisesToWait.push(\n this.store.invalidateObject(obj.objectType, obj.primaryKey),\n );\n\n typesToInvalidate.add(obj.objectType);\n }\n\n await Promise.all(promisesToWait);\n\n // the action invocation just gives back object ids,\n // so we don't want to build the changes object\n // until we have up to date values.\n changes = this.#changesFromActionEditResponse(value);\n\n // updates `changes` in place\n await this.store.maybeRevalidateLists(changes);\n } else {\n for (const apiName of value.editedObjectTypes) {\n typesToInvalidate.add(apiName.toString());\n await this.store.invalidateObjectType(apiName as string, changes);\n }\n }\n\n return value;\n };\n\n #changesFromActionEditResponse = (value: ActionEditResponse) => {\n const changes = createChangedObjects();\n for (const changeType of [\"addedObjects\", \"modifiedObjects\"] as const) {\n for (const { objectType, primaryKey } of (value[changeType] ?? [])) {\n const obj = this.store.getObject(objectType, primaryKey);\n if (obj) {\n changes[changeType].set(objectType, obj);\n }\n }\n }\n return changes;\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,KAAK,QAAQ,KAAK;AAG3B,SAAuBC,oBAAoB,QAAQ,qBAAqB;AACxE,SAASC,gBAAgB,QAAQ,oBAAoB;AAGrD,MAAMC,YAAY,GAAGC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAA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AC;QACxD,IAAIL,GAAG,EAAE;UACPH,OAAO,CAACmB,UAAU,CAAC,CAACE,GAAG,CAACd,UAAU,EAAEJ,GAAG,CAAC;QAC1C;MACF;IACF;IACA,OAAOH,OAAO;EAChB,CAAC;AACH","ignoreList":[]}
@@ -1,2 +1,39 @@
1
- export {};
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /**
18
+ * This isn't performant and should only be used for debug logging!
19
+ * @internal
20
+ */
21
+ export function DEBUG_ONLY__cacheKeyToString(x) {
22
+ if (process.env.NODE_ENV !== "production") {
23
+ return `${x.type}CacheKey<${x.otherKeys.map(xx => JSON.stringify(xx)).join(", ")}>`.replaceAll("\"", "'");
24
+ } else {
25
+ throw new Error("not implemented");
26
+ }
27
+ }
28
+ /**
29
+ * This isn't performant and should only be used for debug logging!
30
+ * @internal
31
+ */
32
+ export function DEBUG_ONLY__cacheKeysToString(x) {
33
+ if (process.env.NODE_ENV !== "production") {
34
+ return JSON.stringify(x.map(DEBUG_ONLY__cacheKeyToString), null, 2);
35
+ } else {
36
+ throw new Error("not implemented");
37
+ }
38
+ }
2
39
  //# sourceMappingURL=CacheKey.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CacheKey.js","names":[],"sources":["CacheKey.ts"],"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 type { Query } from \"./Query.js\";\n\nexport type CacheKey<\n X extends string = string,\n T_StoreValue = unknown,\n T_Query extends Query<any, any, any> = Query<any, any, any>,\n T_KeyFactoryArgs extends any[] = any[],\n> = {\n type: X;\n otherKeys: T_KeyFactoryArgs;\n __cacheKey: {\n value: T_StoreValue;\n query: T_Query;\n args: T_KeyFactoryArgs;\n };\n};\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"CacheKey.js","names":["DEBUG_ONLY__cacheKeyToString","x","process","env","NODE_ENV","type","otherKeys","map","xx","JSON","stringify","join","replaceAll","Error","DEBUG_ONLY__cacheKeysToString"],"sources":["CacheKey.ts"],"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 type { Query } from \"./Query.js\";\n\nexport type CacheKey<\n X extends string = string,\n T_StoreValue = unknown,\n T_Query extends Query<any, any, any> = Query<any, any, any>,\n T_KeyFactoryArgs extends any[] = any[],\n> = {\n type: X;\n otherKeys: T_KeyFactoryArgs;\n __cacheKey: {\n value: T_StoreValue;\n query: T_Query;\n args: T_KeyFactoryArgs;\n };\n};\n\n/**\n * This isn't performant and should only be used for debug logging!\n * @internal\n */\nexport function DEBUG_ONLY__cacheKeyToString(x: CacheKey) {\n if (process.env.NODE_ENV !== \"production\") {\n return `${x.type}CacheKey<${\n x.otherKeys.map(xx => JSON.stringify(xx)).join(\", \")\n }>`.replaceAll(\"\\\"\", \"'\");\n } else {\n throw new Error(\"not implemented\");\n }\n}\n/**\n * This isn't performant and should only be used for debug logging!\n * @internal\n */\nexport function DEBUG_ONLY__cacheKeysToString(x: CacheKey[]) {\n if (process.env.NODE_ENV !== \"production\") {\n return JSON.stringify(x.map(DEBUG_ONLY__cacheKeyToString), null, 2);\n } else {\n throw new Error(\"not implemented\");\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmBA;AACA;AACA;AACA;AACA,OAAO,SAASA,4BAA4BA,CAACC,CAAW,EAAE;EACxD,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzC,OAAO,GAAGH,CAAC,CAACI,IAAI,YACdJ,CAAC,CAACK,SAAS,CAACC,GAAG,CAACC,EAAE,IAAIC,IAAI,CAACC,SAAS,CAACF,EAAE,CAAC,CAAC,CAACG,IAAI,CAAC,IAAI,CAAC,GACnD,CAACC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC;EAC3B,CAAC,MAAM;IACL,MAAM,IAAIC,KAAK,CAAC,iBAAiB,CAAC;EACpC;AACF;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,6BAA6BA,CAACb,CAAa,EAAE;EAC3D,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzC,OAAOK,IAAI,CAACC,SAAS,CAACT,CAAC,CAACM,GAAG,CAACP,4BAA4B,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;EACrE,CAAC,MAAM;IACL,MAAM,IAAIa,KAAK,CAAC,iBAAiB,CAAC;EACpC;AACF","ignoreList":[]}
@@ -28,7 +28,7 @@ export class CacheKeys {
28
28
  });
29
29
  #cacheKeyFactories = new Map();
30
30
  #onCreate;
31
- constructor(whereCanonicalizer, onCreate) {
31
+ constructor(whereCanonicalizer, orderByCanonicalizer, onCreate) {
32
32
  this.#onCreate = onCreate;
33
33
  this.#registerCacheKeyFactory("object", (apiName, pk) => {
34
34
  if (process.env.NODE_ENV !== "production" && DEBUG_CACHE_KEYS) {
@@ -37,12 +37,12 @@ export class CacheKeys {
37
37
  }
38
38
  return this.#cacheKeys.lookupArray(["object", apiName, pk]);
39
39
  });
40
- this.#registerCacheKeyFactory("list", (apiName, where) => {
40
+ this.#registerCacheKeyFactory("list", (apiName, where, orderBy) => {
41
41
  if (process.env.NODE_ENV !== "production" && DEBUG_CACHE_KEYS) {
42
42
  // eslint-disable-next-line no-console
43
- console.debug(`CacheKeys.get([list, ${apiName}, ${JSON.stringify(where)}]) -- already exists? `, this.#cacheKeys.peekArray(["list", apiName, whereCanonicalizer.canonicalize(where)]) != null);
43
+ console.debug(`CacheKeys.get([list, ${apiName}, ${JSON.stringify(where)}, ${JSON.stringify(orderBy)}]) -- already exists? `, this.#cacheKeys.peekArray(["list", apiName, whereCanonicalizer.canonicalize(where), orderByCanonicalizer.canonicalize(orderBy)]) != null);
44
44
  }
45
- return this.#cacheKeys.lookupArray(["list", apiName, whereCanonicalizer.canonicalize(where)]);
45
+ return this.#cacheKeys.lookupArray(["list", apiName, whereCanonicalizer.canonicalize(where), orderByCanonicalizer.canonicalize(orderBy)]);
46
46
  });
47
47
  }
48
48
  #registerCacheKeyFactory(type, factory) {
@@ -1 +1 @@
1
- {"version":3,"file":"CacheKeys.js","names":["Trie","invariant","DEBUG_CACHE_KEYS","CacheKeys","cacheKeys","keys","ret","type","otherKeys","slice","onCreate","cacheKeyFactories","Map","constructor","whereCanonicalizer","registerCacheKeyFactory","apiName","pk","process","env","NODE_ENV","console","debug","peekArray","lookupArray","where","JSON","stringify","canonicalize","#registerCacheKeyFactory","factory","set","get","args","remove","cacheKey"],"sources":["CacheKeys.ts"],"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 { Trie } from \"@wry/trie\";\nimport invariant from \"tiny-invariant\";\nimport { DEBUG_CACHE_KEYS } from \"../DebugFlags.js\";\nimport type { CacheKey } from \"./CacheKey.js\";\nimport type { ListCacheKey } from \"./ListQuery.js\";\nimport type { ObjectCacheKey } from \"./ObjectQuery.js\";\nimport type { WhereClauseCanonicalizer } from \"./WhereClauseCanonicalizer.js\";\n\nexport class CacheKeys {\n #cacheKeys = new Trie<CacheKey<string, any, any>>(false, (keys) => {\n const ret = {\n type: keys[0],\n otherKeys: keys.slice(1),\n } as unknown as CacheKey<\n string,\n any,\n any\n >;\n this.#onCreate(ret);\n return ret;\n });\n #cacheKeyFactories = new Map<string, (...args: any[]) => CacheKey>();\n #onCreate: (cacheKey: CacheKey) => void;\n\n constructor(\n whereCanonicalizer: WhereClauseCanonicalizer,\n onCreate: (cacheKey: CacheKey) => void,\n ) {\n this.#onCreate = onCreate;\n this.#registerCacheKeyFactory<ObjectCacheKey>(\n \"object\",\n (apiName, pk) => {\n if (process.env.NODE_ENV !== \"production\" && DEBUG_CACHE_KEYS) {\n // eslint-disable-next-line no-console\n console.debug(\n `CacheKeys.get([object, ${apiName}, ${pk}]) -- already exists? `,\n this.#cacheKeys.peekArray([\n \"object\",\n apiName,\n pk,\n ]) != null,\n );\n }\n return this.#cacheKeys.lookupArray([\n \"object\",\n apiName,\n pk,\n ]) as ObjectCacheKey;\n },\n );\n this.#registerCacheKeyFactory<ListCacheKey>(\n \"list\",\n (apiName, where) => {\n if (process.env.NODE_ENV !== \"production\" && DEBUG_CACHE_KEYS) {\n // eslint-disable-next-line no-console\n console.debug(\n `CacheKeys.get([list, ${apiName}, ${\n JSON.stringify(where)\n }]) -- already exists? `,\n this.#cacheKeys.peekArray([\n \"list\",\n apiName,\n whereCanonicalizer.canonicalize(where),\n ]) != null,\n );\n }\n return this.#cacheKeys.lookupArray([\n \"list\",\n apiName,\n whereCanonicalizer.canonicalize(where),\n ]) as ListCacheKey;\n },\n );\n }\n\n #registerCacheKeyFactory<K extends CacheKey>(\n type: K[\"type\"],\n factory: (...args: K[\"__cacheKey\"][\"args\"]) => K,\n ): void {\n this.#cacheKeyFactories.set(type, factory);\n }\n\n get<K extends CacheKey<string, any, any>>(\n type: K[\"type\"],\n ...args: K[\"__cacheKey\"][\"args\"]\n ): K {\n const factory = this.#cacheKeyFactories.get(type);\n invariant(factory, `no cache key factory for type \"${type}\"`);\n return factory(...args) as K;\n }\n\n remove<K extends CacheKey<string, any, any>>(\n cacheKey: K,\n ): void {\n this.#cacheKeys.remove(cacheKey.type, ...cacheKey.otherKeys);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,IAAI,QAAQ,WAAW;AAChC,OAAOC,SAAS,MAAM,gBAAgB;AACtC,SAASC,gBAAgB,QAAQ,kBAAkB;AAMnD,OAAO,MAAMC,SAAS,CAAC;EACrB,CAACC,SAAS,GAAG,IAAIJ,IAAI,CAA6B,KAAK,EAAGK,IAAI,IAAK;IACjE,MAAMC,GAAG,GAAG;MACVC,IAAI,EAAEF,IAAI,CAAC,CAAC,CAAC;MACbG,SAAS,EAAEH,IAAI,CAACI,KAAK,CAAC,CAAC;IACzB,CAIC;IACD,IAAI,CAAC,CAACC,QAAQ,CAACJ,GAAG,CAAC;IACnB,OAAOA,GAAG;EACZ,CAAC,CAAC;EACF,CAACK,iBAAiB,GAAG,IAAIC,GAAG,CAAuC,CAAC;EACpE,CAACF,QAAQ;EAETG,WAAWA,CACTC,kB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AAI,EAAEuB,OAAO,CAAC;EAC5C;EAEAE,GAAGA,CACDzB,IAAe,EACf,GAAG0B,IAA6B,EAC7B;IACH,MAAMH,OAAO,GAAG,IAAI,CAAC,CAACnB,iBAAiB,CAACqB,GAAG,CAACzB,IAAI,CAAC;IACjD,CAAUuB,OAAO,GAAAZ,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAjBnB,SAAS,QAAU,kCAAkCM,IAAI,GAAG,IAA5DN,SAAS;IACT,OAAO6B,OAAO,CAAC,GAAGG,IAAI,CAAC;EACzB;EAEAC,MAAMA,CACJC,QAAW,EACL;IACN,IAAI,CAAC,CAAC/B,SAAS,CAAC8B,MAAM,CAACC,QAAQ,CAAC5B,IAAI,EAAE,GAAG4B,QAAQ,CAAC3B,SAAS,CAAC;EAC9D;AACF","ignoreList":[]}
1
+ {"version":3,"file":"CacheKeys.js","names":["Trie","invariant","DEBUG_CACHE_KEYS","CacheKeys","cacheKeys","keys","ret","type","otherKeys","slice","onCreate","cacheKeyFactories","Map","constructor","whereCanonicalizer","orderByCanonicalizer","registerCacheKeyFactory","apiName","pk","process","env","NODE_ENV","console","debug","peekArray","lookupArray","where","orderBy","JSON","stringify","canonicalize","#registerCacheKeyFactory","factory","set","get","args","remove","cacheKey"],"sources":["CacheKeys.ts"],"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 { Trie } from \"@wry/trie\";\nimport invariant from \"tiny-invariant\";\nimport { DEBUG_CACHE_KEYS } from \"../DebugFlags.js\";\nimport type { CacheKey } from \"./CacheKey.js\";\nimport type { ListCacheKey } from \"./ListQuery.js\";\nimport type { ObjectCacheKey } from \"./ObjectQuery.js\";\nimport type { OrderByCanonicalizer } from \"./Store.js\";\nimport type { WhereClauseCanonicalizer } from \"./WhereClauseCanonicalizer.js\";\n\ntype CacheKeyArgs<K extends CacheKey> = [K[\"type\"], ...K[\"otherKeys\"]];\n\nexport class CacheKeys {\n #cacheKeys = new Trie<CacheKey<string, any, any>>(false, (keys) => {\n const ret = {\n type: keys[0],\n otherKeys: keys.slice(1),\n } as unknown as CacheKey<\n string,\n any,\n any\n >;\n this.#onCreate(ret);\n return ret;\n });\n #cacheKeyFactories = new Map<string, (...args: any[]) => CacheKey>();\n #onCreate: (cacheKey: CacheKey) => void;\n\n constructor(\n whereCanonicalizer: WhereClauseCanonicalizer,\n orderByCanonicalizer: OrderByCanonicalizer,\n onCreate: (cacheKey: CacheKey) => void,\n ) {\n this.#onCreate = onCreate;\n this.#registerCacheKeyFactory<ObjectCacheKey>(\n \"object\",\n (apiName, pk) => {\n if (process.env.NODE_ENV !== \"production\" && DEBUG_CACHE_KEYS) {\n // eslint-disable-next-line no-console\n console.debug(\n `CacheKeys.get([object, ${apiName}, ${pk}]) -- already exists? `,\n this.#cacheKeys.peekArray([\n \"object\",\n apiName,\n pk,\n ]) != null,\n );\n }\n return this.#cacheKeys.lookupArray([\n \"object\",\n apiName,\n pk,\n ]) as ObjectCacheKey;\n },\n );\n this.#registerCacheKeyFactory<ListCacheKey>(\n \"list\",\n (apiName, where, orderBy) => {\n if (process.env.NODE_ENV !== \"production\" && DEBUG_CACHE_KEYS) {\n // eslint-disable-next-line no-console\n console.debug(\n `CacheKeys.get([list, ${apiName}, ${JSON.stringify(where)}, ${\n JSON.stringify(orderBy)\n }]) -- already exists? `,\n this.#cacheKeys.peekArray([\n \"list\",\n apiName,\n whereCanonicalizer.canonicalize(where),\n orderByCanonicalizer.canonicalize(orderBy),\n ]) != null,\n );\n }\n return this.#cacheKeys.lookupArray<\n CacheKeyArgs<ListCacheKey>\n >([\n \"list\",\n apiName,\n whereCanonicalizer.canonicalize(where),\n orderByCanonicalizer.canonicalize(orderBy),\n ]) as ListCacheKey;\n },\n );\n }\n\n #registerCacheKeyFactory<K extends CacheKey>(\n type: K[\"type\"],\n factory: (...args: K[\"__cacheKey\"][\"args\"]) => K,\n ): void {\n this.#cacheKeyFactories.set(type, factory);\n }\n\n get<K extends CacheKey<string, any, any>>(\n type: K[\"type\"],\n ...args: K[\"__cacheKey\"][\"args\"]\n ): K {\n const factory = this.#cacheKeyFactories.get(type);\n invariant(factory, `no cache key factory for type \"${type}\"`);\n return factory(...args) as K;\n }\n\n remove<K extends CacheKey<string, any, any>>(\n cacheKey: K,\n ): void {\n this.#cacheKeys.remove(cacheKey.type, ...cacheKey.otherKeys);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,IAAI,QAAQ,WAAW;AAChC,OAAOC,SAAS,MAAM,gBAAgB;AACtC,SAASC,gBAAgB,QAAQ,kBAAkB;AASnD,OAAO,MAAMC,SAAS,CAAC;EACrB,CAACC,SAAS,GAAG,IAAIJ,IAAI,CAA6B,KAAK,EAAGK,IAAI,IAAK;IACjE,MAAMC,GAAG,GAAG;MACVC,IAAI,EAAEF,IAAI,CAAC,CAAC,CAAC;MACbG,SAAS,EAAEH,IAAI,CAACI,KAAK,CAAC,CAAC;IACzB,CAIC;IACD,IAAI,CAAC,CAACC,QAAQ,CAACJ,GAAG,CAAC;IACnB,OAAOA,GAAG;EACZ,CAAC,CAAC;EACF,CAACK,iBAAiB,GAAG,IAAIC,GAAG,CAAuC,CAAC;EACpE,CAACF,QAAQ;EAETG,WAAWA,CACTC,kBAA4C,EAC5CC,oBAA0C,EAC1CL,QAAsC,EACtC;IACA,IAAI,CAAC,CAACA,QAAQ,GAAGA,QAAQ;IACzB,IAAI,CAAC,CAACM,uBAAuB,CAC3B,QAAQ,EACR,CA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iB,CAACsB,GAAG,CAAC1B,IAAI,EAAEyB,OAAO,CAAC;EAC5C;EAEAE,GAAGA,CACD3B,IAAe,EACf,GAAG4B,IAA6B,EAC7B;IACH,MAAMH,OAAO,GAAG,IAAI,CAAC,CAACrB,iBAAiB,CAACuB,GAAG,CAAC3B,IAAI,CAAC;IACjD,CAAUyB,OAAO,GAAAb,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAjBpB,SAAS,QAAU,kCAAkCM,IAAI,GAAG,IAA5DN,SAAS;IACT,OAAO+B,OAAO,CAAC,GAAGG,IAAI,CAAC;EACzB;EAEAC,MAAMA,CACJC,QAAW,EACL;IACN,IAAI,CAAC,CAACjC,SAAS,CAACgC,MAAM,CAACC,QAAQ,CAAC9B,IAAI,EAAE,GAAG8B,QAAQ,CAAC7B,SAAS,CAAC;EAC9D;AACF","ignoreList":[]}
@@ -15,10 +15,33 @@
15
15
  */
16
16
 
17
17
  import { MultiMap } from "mnemonist";
18
+ import { DEBUG_ONLY__cacheKeyToString } from "./CacheKey.js";
18
19
  export function createChangedObjects() {
19
20
  return {
20
21
  modifiedObjects: new MultiMap(),
21
- addedObjects: new MultiMap()
22
+ addedObjects: new MultiMap(),
23
+ addedLists: new Set(),
24
+ modifiedLists: new Set()
22
25
  };
23
26
  }
27
+ export function DEBUG_ONLY__changesToString(changes) {
28
+ if (process.env.NODE_ENV !== "production") {
29
+ return JSON.stringify({
30
+ modifiedObjects: multimapHelper(changes.modifiedObjects),
31
+ addedObjects: multimapHelper(changes.addedObjects),
32
+ addedLists: listHelper(changes.addedLists),
33
+ modifiedLists: listHelper(changes.modifiedLists)
34
+ }, null, 2);
35
+ } else {
36
+ throw new Error("not implemented");
37
+ }
38
+ }
39
+ function listHelper(set) {
40
+ return Array.from(set).map(DEBUG_ONLY__cacheKeyToString);
41
+ }
42
+ function multimapHelper(multimap) {
43
+ return Object.fromEntries(Array.from(multimap.associations()).map(([type, objects]) => {
44
+ return [type, objects.map(o => o.$primaryKey)];
45
+ }));
46
+ }
24
47
  //# sourceMappingURL=ChangedObjects.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ChangedObjects.js","names":["MultiMap","createChangedObjects","modifiedObjects","addedObjects"],"sources":["ChangedObjects.ts"],"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 type { ObjectTypeDefinition, Osdk } from \"@osdk/api\";\nimport { MultiMap } from \"mnemonist\";\n\nexport interface ChangedObjects {\n modifiedObjects: MultiMap<string, Osdk.Instance<ObjectTypeDefinition>>;\n addedObjects: MultiMap<string, Osdk.Instance<ObjectTypeDefinition>>;\n}\n\nexport function createChangedObjects(): ChangedObjects {\n return {\n modifiedObjects: new MultiMap<\n string,\n Osdk.Instance<ObjectTypeDefinition>\n >(),\n addedObjects: new MultiMap<string, Osdk.Instance<ObjectTypeDefinition>>(),\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,QAAQ,QAAQ,WAAW;AAOpC,OAAO,SAASC,oBAAoBA,CAAA,EAAmB;EACrD,OAAO;IACLC,eAAe,EAAE,IAAIF,QAAQ,CAG3B,CAAC;IACHG,YAAY,EAAE,IAAIH,QAAQ,CAA8C;EAC1E,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"ChangedObjects.js","names":["MultiMap","DEBUG_ONLY__cacheKeyToString","createChangedObjects","modifiedObjects","addedObjects","addedLists","Set","modifiedLists","DEBUG_ONLY__changesToString","changes","process","env","NODE_ENV","JSON","stringify","multimapHelper","listHelper","Error","set","Array","from","map","multimap","Object","fromEntries","associations","type","objects","o","$primaryKey"],"sources":["ChangedObjects.ts"],"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 type { ObjectTypeDefinition, Osdk } from \"@osdk/api\";\nimport { MultiMap } from \"mnemonist\";\nimport { DEBUG_ONLY__cacheKeyToString } from \"./CacheKey.js\";\nimport type { ListCacheKey } from \"./ListQuery.js\";\n\nexport interface Changes {\n modifiedObjects: MultiMap<string, Osdk.Instance<ObjectTypeDefinition>>;\n addedObjects: MultiMap<string, Osdk.Instance<ObjectTypeDefinition>>;\n addedLists: Set<ListCacheKey>;\n modifiedLists: Set<ListCacheKey>;\n}\n\nexport function createChangedObjects(): Changes {\n return {\n modifiedObjects: new MultiMap<\n string,\n Osdk.Instance<ObjectTypeDefinition>\n >(),\n addedObjects: new MultiMap<string, Osdk.Instance<ObjectTypeDefinition>>(),\n addedLists: new Set<ListCacheKey>(),\n modifiedLists: new Set<ListCacheKey>(),\n };\n}\n\nexport function DEBUG_ONLY__changesToString(changes: Changes): string {\n if (process.env.NODE_ENV !== \"production\") {\n return JSON.stringify(\n {\n modifiedObjects: multimapHelper(changes.modifiedObjects),\n addedObjects: multimapHelper(changes.addedObjects),\n addedLists: listHelper(changes.addedLists),\n modifiedLists: listHelper(changes.modifiedLists),\n },\n null,\n 2,\n );\n } else {\n throw new Error(\"not implemented\");\n }\n}\n\nfunction listHelper(set: Set<ListCacheKey>) {\n return Array.from(set).map(DEBUG_ONLY__cacheKeyToString);\n}\n\nfunction multimapHelper(\n multimap: MultiMap<string, Osdk.Instance<ObjectTypeDefinition>>,\n) {\n return Object.fromEntries(\n Array.from(multimap.associations()).map(\n ([type, objects]) => {\n return [type, objects.map(o => o.$primaryKey)];\n },\n ),\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,QAAQ,QAAQ,WAAW;AACpC,SAASC,4BAA4B,QAAQ,eAAe;AAU5D,OAAO,SAASC,oBAAoBA,CAAA,EAAY;EAC9C,OAAO;IACLC,eAAe,EAAE,IAAIH,QAAQ,CAG3B,CAAC;IACHI,YAAY,EAAE,IAAIJ,QAAQ,CAA8C,CAAC;IACzEK,UAAU,EAAE,IAAIC,GAAG,CAAe,CAAC;IACnCC,aAAa,EAAE,IAAID,GAAG,CAAe;EACvC,CAAC;AACH;AAEA,OAAO,SAASE,2BAA2BA,CAACC,OAAgB,EAAU;EACpE,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzC,OAAOC,IAAI,CAACC,SAAS,CACnB;MACEX,eAAe,EAAEY,cAAc,CAACN,OAAO,CAACN,eAAe,CAAC;MACxDC,YAAY,EAAEW,cAAc,CAACN,OAAO,CAACL,YAAY,CAAC;MAClDC,UAAU,EAAEW,UAAU,CAACP,OAAO,CAACJ,UAAU,CAAC;MAC1CE,aAAa,EAAES,UAAU,CAACP,OAAO,CAACF,aAAa;IACjD,CAAC,EACD,IAAI,EACJ,CACF,CAAC;EACH,CAAC,MAAM;IACL,MAAM,IAAIU,KAAK,CAAC,iBAAiB,CAAC;EACpC;AACF;AAEA,SAASD,UAAUA,CAACE,GAAsB,EAAE;EAC1C,OAAOC,KAAK,CAACC,IAAI,CAACF,GAAG,CAAC,CAACG,GAAG,CAACpB,4BAA4B,CAAC;AAC1D;AAEA,SAASc,cAAcA,CACrBO,QAA+D,EAC/D;EACA,OAAOC,MAAM,CAACC,WAAW,CACvBL,KAAK,CAACC,IAAI,CAACE,QAAQ,CAACG,YAAY,CAAC,CAAC,CAAC,CAACJ,GAAG,CACrC,CAAC,CAACK,IAAI,EAAEC,OAAO,CAAC,KAAK;IACnB,OAAO,CAACD,IAAI,EAAEC,OAAO,CAACN,GAAG,CAACO,CAAC,IAAIA,CAAC,CAACC,WAAW,CAAC,CAAC;EAChD,CACF,CACF,CAAC;AACH","ignoreList":[]}
@@ -53,7 +53,7 @@ export class Layer {
53
53
  this.#parent = this.#parent.removeLayer(layerId);
54
54
  return this;
55
55
  }
56
- return this.#parent ?? this;
56
+ return this.#parent.removeLayer(layerId);
57
57
  }
58
58
  entries() {
59
59
  return this.#cache.entries();
@@ -66,11 +66,11 @@ export class Layer {
66
66
  }
67
67
  }
68
68
  export class Entry {
69
- constructor(cacheKey, value, lastUpdated) {
69
+ constructor(cacheKey, value, lastUpdated, status = "init") {
70
70
  this.cacheKey = cacheKey;
71
71
  this.value = value;
72
72
  this.lastUpdated = lastUpdated;
73
- this.status = "init";
73
+ this.status = status;
74
74
  }
75
75
  }
76
76
  //# sourceMappingURL=Layer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Layer.js","names":["WeakMapWithEntries","Layer","parent","cache","layerId","constructor","parentLayer","addLayer","removeLayer","entries","get","cacheKey","set","value","Entry","lastUpdated","status"],"sources":["Layer.ts"],"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 type { CacheKey } from \"./CacheKey.js\";\nimport { WeakMapWithEntries } from \"./WeakMapWithEntries.js\";\n\n/*\n Image some layers\n\n [\n { cache: { obj1: { a: 1 } }, layerId: undefined },\n { cache: { obj1: { a: 1, b: 2 } }, layerId: \"layer1\" },\n { cache: { obj1: { a: undefined, b: 2 } }, layerId: \"layer2\" },\n { cache: { obj1: { a: 1, b: 2 } }, layerId: \"layer3\" },\n ]\n*/\n\nexport class Layer {\n #parent: Layer | undefined;\n #cache = new WeakMapWithEntries<CacheKey<string, any, any>, Entry<any>>();\n #layerId: unknown;\n\n constructor(parent: Layer | undefined, layerId: unknown) {\n this.#parent = parent;\n this.#layerId = layerId;\n }\n\n get parentLayer(): Layer | undefined {\n return this.#parent;\n }\n\n get layerId(): unknown {\n return this.#layerId;\n }\n\n addLayer(layerId: unknown): Layer {\n return new Layer(this, layerId);\n }\n\n removeLayer(layerId: unknown): Layer {\n if (layerId == null || this.#parent == null) {\n // we are the root, so we can't remove anything\n return this;\n }\n if (this.#layerId !== layerId) {\n this.#parent = this.#parent.removeLayer(layerId);\n return this;\n }\n\n return this.#parent ?? this;\n }\n\n entries(): IterableIterator<[CacheKey<string, any, any>, Entry<any>]> {\n return this.#cache.entries();\n }\n\n public get<K extends CacheKey<string, unknown, any>>(\n cacheKey: K,\n ): Entry<K> | undefined {\n return this.#cache.get(cacheKey) as Entry<K> | undefined\n ?? this.#parent?.get(cacheKey) as Entry<K> | undefined;\n }\n\n public set<K extends CacheKey<string, unknown, any>>(\n cacheKey: K,\n value: Entry<K>,\n ): void {\n this.#cache.set(cacheKey, value);\n }\n}\n\nexport class Entry<K extends CacheKey<any, any, any>> {\n readonly cacheKey: K;\n value: K[\"__cacheKey\"][\"value\"] | undefined;\n lastUpdated: number;\n status: \"init\" | \"loading\" | \"loaded\" | \"error\";\n\n constructor(\n cacheKey: K,\n value: K[\"__cacheKey\"][\"value\"],\n lastUpdated: number,\n ) {\n this.cacheKey = cacheKey;\n this.value = value;\n this.lastUpdated = lastUpdated;\n this.status = \"init\";\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;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MAAM,EAAEQ,GAAG,CAACC,QAAQ,CAAyB;EAC1D;EAEOC,GAAGA,CACRD,QAAW,EACXE,KAAe,EACT;IACN,IAAI,CAAC,CAACV,KAAK,CAACS,GAAG,CAACD,QAAQ,EAAEE,KAAK,CAAC;EAClC;AACF;AAEA,OAAO,MAAMC,KAAK,CAAoC;EAMpDT,WAAWA,CACTM,QAAW,EACXE,KAA+B,EAC/BE,WAAmB,EACnB;IACA,IAAI,CAACJ,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACE,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACE,WAAW,GAAGA,WAAW;IAC9B,IAAI,CAACC,MAAM,GAAG,MAAM;EACtB;AACF","ignoreList":[]}
1
+ {"version":3,"file":"Layer.js","names":["WeakMapWithEntries","Layer","parent","cache","layerId","constructor","parentLayer","addLayer","removeLayer","entries","get","cacheKey","set","value","Entry","lastUpdated","status"],"sources":["Layer.ts"],"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 type { CacheKey } from \"./CacheKey.js\";\nimport { WeakMapWithEntries } from \"./WeakMapWithEntries.js\";\n\n/*\n Image some layers\n\n [\n { cache: { obj1: { a: 1 } }, layerId: undefined },\n { cache: { obj1: { a: 1, b: 2 } }, layerId: \"layer1\" },\n { cache: { obj1: { a: undefined, b: 2 } }, layerId: \"layer2\" },\n { cache: { obj1: { a: 1, b: 2 } }, layerId: \"layer3\" },\n ]\n*/\n\nexport class Layer {\n #parent: Layer | undefined;\n #cache = new WeakMapWithEntries<CacheKey<string, any, any>, Entry<any>>();\n #layerId: unknown;\n\n constructor(parent: Layer | undefined, layerId: unknown) {\n this.#parent = parent;\n this.#layerId = layerId;\n }\n\n get parentLayer(): Layer | undefined {\n return this.#parent;\n }\n\n get layerId(): unknown {\n return this.#layerId;\n }\n\n addLayer(layerId: unknown): Layer {\n return new Layer(this, layerId);\n }\n\n removeLayer(layerId: unknown): Layer {\n if (layerId == null || this.#parent == null) {\n // we are the root, so we can't remove anything\n return this;\n }\n\n if (this.#layerId !== layerId) {\n this.#parent = this.#parent.removeLayer(layerId);\n return this;\n }\n\n return this.#parent.removeLayer(layerId);\n }\n\n entries(): IterableIterator<[CacheKey<string, any, any>, Entry<any>]> {\n return this.#cache.entries();\n }\n\n public get<K extends CacheKey<string, unknown, any>>(\n cacheKey: K,\n ): Entry<K> | undefined {\n return this.#cache.get(cacheKey) as Entry<K> | undefined\n ?? this.#parent?.get(cacheKey) as Entry<K> | undefined;\n }\n\n public set<K extends CacheKey<string, unknown, any>>(\n cacheKey: K,\n value: Entry<K>,\n ): void {\n this.#cache.set(cacheKey, value);\n }\n}\n\nexport class Entry<K extends CacheKey<any, any, any>> {\n readonly cacheKey: K;\n value: K[\"__cacheKey\"][\"value\"] | undefined;\n lastUpdated: number;\n status: \"init\" | \"loading\" | \"loaded\" | \"error\";\n\n constructor(\n cacheKey: K,\n value: K[\"__cacheKey\"][\"value\"],\n lastUpdated: number,\n status: \"init\" | \"loading\" | \"loaded\" | \"error\" = \"init\",\n ) {\n this.cacheKey = cacheKey;\n this.value = value;\n this.lastUpdated = lastUpdated;\n this.status = status;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,kBAAkB,QAAQ,yBAAyB;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMC,KAAK,CAAC;EACjB,CAACC,MAAM;EACP,CAACC,KAAK,GAAG,IAAIH,k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