@aglyn/tenant-feature-instance 1.0.0-beta.217 → 1.0.0-beta.219

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.
@@ -23,19 +23,9 @@ import { Timestamp } from "@aglyn/shared-util-timestamp";
23
23
  import { Bytes, doc } from "firebase/firestore";
24
24
  import { useFirestore } from "./firebase/firebase-services.js";
25
25
  import useDoc from "./helpers/use-doc.js";
26
- /**
27
- * A form's working version, at
28
- * `hosts/{hostId}/forms/{formId}/versions/{versionId}`.
29
- *
30
- * Compressed at rest, and carrying the same asymmetry a component version
31
- * does: the PUBLISHED tree lives on the parent `forms/{formId}` document,
32
- * because a placed form has to resolve on the hot path of a page render and
33
- * one collection query reaches every form on the site. These documents are
34
- * editing history — the besigner's draft surface — and nothing renders from
35
- * them.
36
- */ export const useFormVersionRef = ({ hostId, formId, versionId })=>{
26
+ export const useHostDocumentVersionRef = ({ hostId, collection, docId, versionId })=>{
37
27
  const firestore = useFirestore();
38
- const ref = doc(firestore, 'hosts', hostId, 'forms', formId, 'versions', versionId);
28
+ const ref = doc(firestore, 'hosts', hostId, collection, docId, 'versions', versionId);
39
29
  return ref.withConverter({
40
30
  toFirestore (data) {
41
31
  const { $id } = data, rest = _object_without_properties_loose(data, [
@@ -65,9 +55,9 @@ import useDoc from "./helpers/use-doc.js";
65
55
  }
66
56
  });
67
57
  };
68
- export const useFormVersion = (data, options)=>{
69
- return useDoc(useFormVersionRef(data), options);
58
+ export const useHostDocumentVersion = (ids, options)=>{
59
+ return useDoc(useHostDocumentVersionRef(ids), options);
70
60
  };
71
- export default useFormVersion;
61
+ export default useHostDocumentVersion;
72
62
 
73
- //# sourceMappingURL=use-form-version.js.map
63
+ //# sourceMappingURL=use-host-document-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/tenant/feature/instance/src/lib/hooks/use-host-document-version.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\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// A TYPE-only namespace: every `Aglyn.` reference below is a type, and held\n// as a VALUE the namespace pins every module the barrel reaches into the\n// console shell that renders these hooks. `import type` erases instead.\nimport type * as Aglyn from '@aglyn/aglyn'\nimport { compress, decompress } from '@aglyn/aglyn'\nimport { Timestamp } from '@aglyn/shared-util-timestamp'\nimport type { DocumentReference } from 'firebase/firestore'\nimport { Bytes, doc } from 'firebase/firestore'\nimport {\n useFirestore,\n type FirestoreDocOptions,\n} from './firebase/firebase-services'\nimport useDoc from './helpers/use-doc'\n\n/**\n * A plugin document's working version, at\n * `hosts/{hostId}/{collection}/{docId}/versions/{versionId}` — the storage a\n * kind declared in `besignerDocuments` keeps (`plugin-manager/\n * besigner-documents.ts`).\n *\n * Compressed at rest, and carrying the same asymmetry a component version\n * does: the PUBLISHED tree lives on the parent document, because a placed\n * document has to resolve on the hot path of a page render and one\n * collection query reaches every one on the site. These documents are\n * editing history — the besigner's draft surface — and nothing renders from\n * them.\n */\nexport interface HostDocumentVersion {\n displayName?: string\n /** The node a placed copy grafts from; absent on a tree never published. */\n rootId?: Aglyn.NodeId\n nodes?: Record<Aglyn.NodeId, Aglyn.AglynNodeSchema>\n updatedAt?: unknown\n}\n\nexport interface HostDocumentVersionIds {\n hostId: string\n /** The subcollection under `hosts/{hostId}` the document lives in. */\n collection: string\n docId: string\n versionId: string\n}\n\nexport const useHostDocumentVersionRef = ({\n hostId,\n collection,\n docId,\n versionId,\n}: HostDocumentVersionIds) => {\n const firestore = useFirestore()\n const ref = doc(\n firestore,\n 'hosts',\n hostId,\n collection,\n docId,\n 'versions',\n versionId,\n )\n return ref.withConverter({\n toFirestore(data) {\n const { $id, ...rest } = data\n // Only emit `nodes` when the write carries them — see the note in\n // use-screen-version (AGL-1250). A partial write that compressed\n // `undefined` would replace the stored tree with an empty one.\n if (rest?.nodes === undefined)\n return { ...rest, updatedAt: Timestamp.now() }\n const nodes =\n rest.nodes instanceof Bytes\n ? rest.nodes\n : Bytes.fromUint8Array(compress(rest.nodes))\n return { ...rest, nodes, updatedAt: Timestamp.now() }\n },\n fromFirestore(snapshot, options) {\n if (!snapshot.exists()) return undefined\n const data = snapshot.data(options)\n if (data?.nodes instanceof Bytes) {\n return {\n ...data,\n nodes: decompress(data.nodes),\n } as HostDocumentVersion\n }\n return data as HostDocumentVersion\n },\n }) as DocumentReference<HostDocumentVersion>\n}\n\nexport const useHostDocumentVersion = (\n ids: HostDocumentVersionIds,\n options?: FirestoreDocOptions<HostDocumentVersion>,\n) => {\n return useDoc(useHostDocumentVersionRef(ids), options)\n}\n\nexport default useHostDocumentVersion\n"],"names":["compress","decompress","Timestamp","Bytes","doc","useFirestore","useDoc","useHostDocumentVersionRef","hostId","collection","docId","versionId","firestore","ref","withConverter","toFirestore","data","$id","rest","nodes","undefined","updatedAt","now","fromUint8Array","fromFirestore","snapshot","options","exists","useHostDocumentVersion","ids"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,4EAA4E;AAC5E,yEAAyE;AACzE,wEAAwE;;;AAExE,SAASA,QAAQ,EAAEC,UAAU,QAAQ,eAAc;AACnD,SAASC,SAAS,QAAQ,+BAA8B;AAExD,SAASC,KAAK,EAAEC,GAAG,QAAQ,qBAAoB;AAC/C,SACEC,YAAY,QAEP,kCAA8B;AACrC,OAAOC,YAAY,uBAAmB;AA+BtC,OAAO,MAAMC,4BAA4B,CAAC,EACxCC,MAAM,EACNC,UAAU,EACVC,KAAK,EACLC,SAAS,EACc;IACvB,MAAMC,YAAYP;IAClB,MAAMQ,MAAMT,IACVQ,WACA,SACAJ,QACAC,YACAC,OACA,YACAC;IAEF,OAAOE,IAAIC,aAAa,CAAC;QACvBC,aAAYC,IAAI;YACd,MAAM,EAAEC,GAAG,EAAW,GAAGD,MAATE,wCAASF;;;YACzB,kEAAkE;YAClE,iEAAiE;YACjE,+DAA+D;YAC/D,IAAIE,CAAAA,wBAAAA,KAAMC,KAAK,MAAKC,WAClB,OAAO,aAAKF;gBAAMG,WAAWnB,UAAUoB,GAAG;;YAC5C,MAAMH,QACJD,KAAKC,KAAK,YAAYhB,QAClBe,KAAKC,KAAK,GACVhB,MAAMoB,cAAc,CAACvB,SAASkB,KAAKC,KAAK;YAC9C,OAAO,aAAKD;gBAAMC;gBAAOE,WAAWnB,UAAUoB,GAAG;;QACnD;QACAE,eAAcC,QAAQ,EAAEC,OAAO;YAC7B,IAAI,CAACD,SAASE,MAAM,IAAI,OAAOP;YAC/B,MAAMJ,OAAOS,SAAST,IAAI,CAACU;YAC3B,IAAIV,CAAAA,wBAAAA,KAAMG,KAAK,aAAYhB,OAAO;gBAChC,OAAO,aACFa;oBACHG,OAAOlB,WAAWe,KAAKG,KAAK;;YAEhC;YACA,OAAOH;QACT;IACF;AACF,EAAC;AAED,OAAO,MAAMY,yBAAyB,CACpCC,KACAH;IAEA,OAAOpB,OAAOC,0BAA0BsB,MAAMH;AAChD,EAAC;AAED,eAAeE,uBAAsB"}
@@ -83,6 +83,7 @@ export declare const useHostRef: ({ hostId }: {
83
83
  advertising?: boolean;
84
84
  };
85
85
  screens?: Record<Aglyn.ScreenUid, Aglyn.ScreenSlug>;
86
+ defaultHomeScreenId?: Aglyn.ScreenUid;
86
87
  notFoundScreenId?: Aglyn.ScreenUid;
87
88
  errorScreens?: Aglyn.HostErrorScreens;
88
89
  authScreens?: import("@aglyn/aglyn/src/lib/foundation/definitions/platform.types").HostAuthScreens;
@@ -91,6 +92,7 @@ export declare const useHostRef: ({ hostId }: {
91
92
  suspendedReasonCode?: string;
92
93
  suspendedMessage?: string;
93
94
  suspendedUntilMs?: number;
95
+ suspended?: boolean;
94
96
  disabledPlugins?: string[];
95
97
  enabledPlugins?: string[];
96
98
  approvedImageHosts?: string[];
@@ -41,7 +41,7 @@ export * from './hooks/use-host-activity-logger';
41
41
  export * from './hooks/use-live-artifact-count';
42
42
  export * from './hooks/use-component';
43
43
  export * from './hooks/use-component-version';
44
- export * from './hooks/use-form-version';
44
+ export * from './hooks/use-host-document-version';
45
45
  export * from './hooks/use-host-template';
46
46
  export * from './hooks/use-console-host-route';
47
47
  export * from './hooks/use-host-org-id';
package/src/lib/tenant.js CHANGED
@@ -40,7 +40,7 @@ export * from "./hooks/use-host-activity-logger.js";
40
40
  export * from "./hooks/use-live-artifact-count.js";
41
41
  export * from "./hooks/use-component.js";
42
42
  export * from "./hooks/use-component-version.js";
43
- export * from "./hooks/use-form-version.js";
43
+ export * from "./hooks/use-host-document-version.js";
44
44
  export * from "./hooks/use-host-template.js";
45
45
  export * from "./hooks/use-console-host-route.js";
46
46
  export * from "./hooks/use-host-org-id.js";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/tenant/feature/instance/src/lib/tenant.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\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 * from './constants/mock-data'\nexport * from './constants/site-paths'\nexport * from './constants/firebase-config'\nexport * from './constants/firebase-emulator-hosts'\n\nexport * from './hooks/firebase/auth-persistence'\nexport * from './hooks/firebase/firebase-services'\nexport * from './hooks/firebase/firestore-cache'\nexport * from './hooks/firebase/firestore-stall-recovery'\nexport * from './hooks/firebase/firestore-bounded-read'\nexport * from './hooks/helpers/use-doc'\nexport * from './hooks/helpers/use-modify-doc-callback'\nexport * from './hooks/helpers/besigner-nodes-converter'\nexport * from './hooks/helpers/guarded-nodes-save'\nexport * from './hooks/helpers/guarded-seed-write'\n\nexport * from './hooks/firestore-denial-reporter'\nexport * from './hooks/use-firestore-collection'\nexport * from './hooks/use-paged-collection'\nexport * from './hooks/use-sorted-paged-collection'\nexport * from './hooks/sorted-collection-window'\nexport * from './hooks/host-collection-queries'\nexport * from './hooks/list-filter-constraints'\nexport * from './hooks/use-firestore-doc'\nexport * from './hooks/use-switcher-collection'\nexport * from './hooks/use-host-activity-logger'\nexport * from './hooks/use-live-artifact-count'\nexport * from './hooks/use-component'\nexport * from './hooks/use-component-version'\nexport * from './hooks/use-form-version'\nexport * from './hooks/use-host-template'\nexport * from './hooks/use-console-host-route'\nexport * from './hooks/use-host-org-id'\nexport * from './hooks/use-host-campaigns'\nexport * from './hooks/use-org-member-options'\nexport * from './hooks/use-org-plan'\nexport * from './hooks/use-scope-tokens'\nexport * from './hooks/use-host-resource-api'\nexport * from './hooks/use-host-version-api'\nexport * from './hooks/use-duplicate-resource-api'\nexport * from './hooks/use-plugin-api-post'\nexport * from './components/duplicate-resource-dialog'\nexport * from './hooks/use-plugin-config'\nexport * from './hooks/use-host'\nexport * from './hooks/use-layout'\nexport * from './hooks/use-layout-version'\nexport * from './hooks/use-screen'\nexport * from './hooks/use-screen-version'\nexport * from './hooks/use-user-name'\nexport * from './hooks/use-user-photo'\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,cAAc,2BAAuB;AACrC,cAAc,4BAAwB;AACtC,cAAc,iCAA6B;AAC3C,cAAc,yCAAqC;AAEnD,cAAc,uCAAmC;AACjD,cAAc,wCAAoC;AAClD,cAAc,sCAAkC;AAChD,cAAc,+CAA2C;AACzD,cAAc,6CAAyC;AACvD,cAAc,6BAAyB;AACvC,cAAc,6CAAyC;AACvD,cAAc,8CAA0C;AACxD,cAAc,wCAAoC;AAClD,cAAc,wCAAoC;AAElD,cAAc,uCAAmC;AACjD,cAAc,sCAAkC;AAChD,cAAc,kCAA8B;AAC5C,cAAc,yCAAqC;AACnD,cAAc,sCAAkC;AAChD,cAAc,qCAAiC;AAC/C,cAAc,qCAAiC;AAC/C,cAAc,+BAA2B;AACzC,cAAc,qCAAiC;AAC/C,cAAc,sCAAkC;AAChD,cAAc,qCAAiC;AAC/C,cAAc,2BAAuB;AACrC,cAAc,mCAA+B;AAC7C,cAAc,8BAA0B;AACxC,cAAc,+BAA2B;AACzC,cAAc,oCAAgC;AAC9C,cAAc,6BAAyB;AACvC,cAAc,gCAA4B;AAC1C,cAAc,oCAAgC;AAC9C,cAAc,0BAAsB;AACpC,cAAc,8BAA0B;AACxC,cAAc,mCAA+B;AAC7C,cAAc,kCAA8B;AAC5C,cAAc,wCAAoC;AAClD,cAAc,iCAA6B;AAC3C,cAAc,4CAAwC;AACtD,cAAc,+BAA2B;AACzC,cAAc,sBAAkB;AAChC,cAAc,wBAAoB;AAClC,cAAc,gCAA4B;AAC1C,cAAc,wBAAoB;AAClC,cAAc,gCAA4B;AAC1C,cAAc,2BAAuB;AACrC,cAAc,4BAAwB"}
1
+ {"version":3,"sources":["../../../../../../../libs/tenant/feature/instance/src/lib/tenant.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\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 * from './constants/mock-data'\nexport * from './constants/site-paths'\nexport * from './constants/firebase-config'\nexport * from './constants/firebase-emulator-hosts'\n\nexport * from './hooks/firebase/auth-persistence'\nexport * from './hooks/firebase/firebase-services'\nexport * from './hooks/firebase/firestore-cache'\nexport * from './hooks/firebase/firestore-stall-recovery'\nexport * from './hooks/firebase/firestore-bounded-read'\nexport * from './hooks/helpers/use-doc'\nexport * from './hooks/helpers/use-modify-doc-callback'\nexport * from './hooks/helpers/besigner-nodes-converter'\nexport * from './hooks/helpers/guarded-nodes-save'\nexport * from './hooks/helpers/guarded-seed-write'\n\nexport * from './hooks/firestore-denial-reporter'\nexport * from './hooks/use-firestore-collection'\nexport * from './hooks/use-paged-collection'\nexport * from './hooks/use-sorted-paged-collection'\nexport * from './hooks/sorted-collection-window'\nexport * from './hooks/host-collection-queries'\nexport * from './hooks/list-filter-constraints'\nexport * from './hooks/use-firestore-doc'\nexport * from './hooks/use-switcher-collection'\nexport * from './hooks/use-host-activity-logger'\nexport * from './hooks/use-live-artifact-count'\nexport * from './hooks/use-component'\nexport * from './hooks/use-component-version'\nexport * from './hooks/use-host-document-version'\nexport * from './hooks/use-host-template'\nexport * from './hooks/use-console-host-route'\nexport * from './hooks/use-host-org-id'\nexport * from './hooks/use-host-campaigns'\nexport * from './hooks/use-org-member-options'\nexport * from './hooks/use-org-plan'\nexport * from './hooks/use-scope-tokens'\nexport * from './hooks/use-host-resource-api'\nexport * from './hooks/use-host-version-api'\nexport * from './hooks/use-duplicate-resource-api'\nexport * from './hooks/use-plugin-api-post'\nexport * from './components/duplicate-resource-dialog'\nexport * from './hooks/use-plugin-config'\nexport * from './hooks/use-host'\nexport * from './hooks/use-layout'\nexport * from './hooks/use-layout-version'\nexport * from './hooks/use-screen'\nexport * from './hooks/use-screen-version'\nexport * from './hooks/use-user-name'\nexport * from './hooks/use-user-photo'\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,cAAc,2BAAuB;AACrC,cAAc,4BAAwB;AACtC,cAAc,iCAA6B;AAC3C,cAAc,yCAAqC;AAEnD,cAAc,uCAAmC;AACjD,cAAc,wCAAoC;AAClD,cAAc,sCAAkC;AAChD,cAAc,+CAA2C;AACzD,cAAc,6CAAyC;AACvD,cAAc,6BAAyB;AACvC,cAAc,6CAAyC;AACvD,cAAc,8CAA0C;AACxD,cAAc,wCAAoC;AAClD,cAAc,wCAAoC;AAElD,cAAc,uCAAmC;AACjD,cAAc,sCAAkC;AAChD,cAAc,kCAA8B;AAC5C,cAAc,yCAAqC;AACnD,cAAc,sCAAkC;AAChD,cAAc,qCAAiC;AAC/C,cAAc,qCAAiC;AAC/C,cAAc,+BAA2B;AACzC,cAAc,qCAAiC;AAC/C,cAAc,sCAAkC;AAChD,cAAc,qCAAiC;AAC/C,cAAc,2BAAuB;AACrC,cAAc,mCAA+B;AAC7C,cAAc,uCAAmC;AACjD,cAAc,+BAA2B;AACzC,cAAc,oCAAgC;AAC9C,cAAc,6BAAyB;AACvC,cAAc,gCAA4B;AAC1C,cAAc,oCAAgC;AAC9C,cAAc,0BAAsB;AACpC,cAAc,8BAA0B;AACxC,cAAc,mCAA+B;AAC7C,cAAc,kCAA8B;AAC5C,cAAc,wCAAoC;AAClD,cAAc,iCAA6B;AAC3C,cAAc,4CAAwC;AACtD,cAAc,+BAA2B;AACzC,cAAc,sBAAkB;AAChC,cAAc,wBAAoB;AAClC,cAAc,gCAA4B;AAC1C,cAAc,wBAAoB;AAClC,cAAc,gCAA4B;AAC1C,cAAc,2BAAuB;AACrC,cAAc,4BAAwB"}
@@ -1,44 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2026 Aglyn LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- import type * as Aglyn from '@aglyn/aglyn';
18
- import type { DocumentReference } from 'firebase/firestore';
19
- import { type FirestoreDocOptions } from './firebase/firebase-services';
20
- /**
21
- * A form's working version, at
22
- * `hosts/{hostId}/forms/{formId}/versions/{versionId}`.
23
- *
24
- * Compressed at rest, and carrying the same asymmetry a component version
25
- * does: the PUBLISHED tree lives on the parent `forms/{formId}` document,
26
- * because a placed form has to resolve on the hot path of a page render and
27
- * one collection query reaches every form on the site. These documents are
28
- * editing history — the besigner's draft surface — and nothing renders from
29
- * them.
30
- */
31
- export declare const useFormVersionRef: ({ hostId, formId, versionId, }: {
32
- hostId: string;
33
- formId: string;
34
- versionId: string;
35
- }) => DocumentReference<Aglyn.FormVersion>;
36
- export declare const useFormVersion: (data: {
37
- hostId: string;
38
- formId: string;
39
- versionId: string;
40
- }, options?: FirestoreDocOptions<Aglyn.FormVersion>) => {
41
- doc: import("./firebase/firebase-services").ObservableStatus<Aglyn.FormVersion<Aglyn.AglynNodeSchema<Partial<Record<JSX.Key.Any, unknown>>>>>;
42
- setDoc: import("./helpers/use-modify-doc-callback").ModifyDocCallback<Aglyn.FormVersion<Aglyn.AglynNodeSchema<Partial<Record<JSX.Key.Any, unknown>>>>>;
43
- };
44
- export default useFormVersion;
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../../../../libs/tenant/feature/instance/src/lib/hooks/use-form-version.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\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// A TYPE-only namespace: every `Aglyn.` reference below is a type, and held\n// as a VALUE the namespace pins every module the barrel reaches into the\n// console shell that renders these hooks. `import type` erases instead.\nimport type * as Aglyn from '@aglyn/aglyn'\nimport { compress, decompress } from '@aglyn/aglyn'\nimport { Timestamp } from '@aglyn/shared-util-timestamp'\nimport type { DocumentReference } from 'firebase/firestore'\nimport { Bytes, doc } from 'firebase/firestore'\nimport {\n useFirestore,\n type FirestoreDocOptions,\n} from './firebase/firebase-services'\nimport useDoc from './helpers/use-doc'\n\n/**\n * A form's working version, at\n * `hosts/{hostId}/forms/{formId}/versions/{versionId}`.\n *\n * Compressed at rest, and carrying the same asymmetry a component version\n * does: the PUBLISHED tree lives on the parent `forms/{formId}` document,\n * because a placed form has to resolve on the hot path of a page render and\n * one collection query reaches every form on the site. These documents are\n * editing history — the besigner's draft surface — and nothing renders from\n * them.\n */\nexport const useFormVersionRef = ({\n hostId,\n formId,\n versionId,\n}: {\n hostId: string\n formId: string\n versionId: string\n}) => {\n const firestore = useFirestore()\n const ref = doc(\n firestore,\n 'hosts',\n hostId,\n 'forms',\n formId,\n 'versions',\n versionId,\n )\n return ref.withConverter({\n toFirestore(data) {\n const { $id, ...rest } = data\n // Only emit `nodes` when the write carries them — see the note in\n // use-screen-version (AGL-1250). A partial write that compressed\n // `undefined` would replace the stored tree with an empty one.\n if (rest?.nodes === undefined)\n return { ...rest, updatedAt: Timestamp.now() }\n const nodes =\n rest.nodes instanceof Bytes\n ? rest.nodes\n : Bytes.fromUint8Array(compress(rest.nodes))\n return { ...rest, nodes, updatedAt: Timestamp.now() }\n },\n fromFirestore(snapshot, options) {\n if (!snapshot.exists()) return undefined\n const data = snapshot.data(options)\n if (data?.nodes instanceof Bytes) {\n return {\n ...data,\n nodes: decompress(data.nodes),\n } as Aglyn.FormVersion\n }\n return data as Aglyn.FormVersion\n },\n }) as DocumentReference<Aglyn.FormVersion>\n}\n\nexport const useFormVersion = (\n data: {\n hostId: string\n formId: string\n versionId: string\n },\n options?: FirestoreDocOptions<Aglyn.FormVersion>,\n) => {\n return useDoc(useFormVersionRef(data), options)\n}\n\nexport default useFormVersion\n"],"names":["compress","decompress","Timestamp","Bytes","doc","useFirestore","useDoc","useFormVersionRef","hostId","formId","versionId","firestore","ref","withConverter","toFirestore","data","$id","rest","nodes","undefined","updatedAt","now","fromUint8Array","fromFirestore","snapshot","options","exists","useFormVersion"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,4EAA4E;AAC5E,yEAAyE;AACzE,wEAAwE;;;AAExE,SAASA,QAAQ,EAAEC,UAAU,QAAQ,eAAc;AACnD,SAASC,SAAS,QAAQ,+BAA8B;AAExD,SAASC,KAAK,EAAEC,GAAG,QAAQ,qBAAoB;AAC/C,SACEC,YAAY,QAEP,kCAA8B;AACrC,OAAOC,YAAY,uBAAmB;AAEtC;;;;;;;;;;CAUC,GACD,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,MAAM,EACNC,MAAM,EACNC,SAAS,EAKV;IACC,MAAMC,YAAYN;IAClB,MAAMO,MAAMR,IACVO,WACA,SACAH,QACA,SACAC,QACA,YACAC;IAEF,OAAOE,IAAIC,aAAa,CAAC;QACvBC,aAAYC,IAAI;YACd,MAAM,EAAEC,GAAG,EAAW,GAAGD,MAATE,wCAASF;;;YACzB,kEAAkE;YAClE,iEAAiE;YACjE,+DAA+D;YAC/D,IAAIE,CAAAA,wBAAAA,KAAMC,KAAK,MAAKC,WAClB,OAAO,aAAKF;gBAAMG,WAAWlB,UAAUmB,GAAG;;YAC5C,MAAMH,QACJD,KAAKC,KAAK,YAAYf,QAClBc,KAAKC,KAAK,GACVf,MAAMmB,cAAc,CAACtB,SAASiB,KAAKC,KAAK;YAC9C,OAAO,aAAKD;gBAAMC;gBAAOE,WAAWlB,UAAUmB,GAAG;;QACnD;QACAE,eAAcC,QAAQ,EAAEC,OAAO;YAC7B,IAAI,CAACD,SAASE,MAAM,IAAI,OAAOP;YAC/B,MAAMJ,OAAOS,SAAST,IAAI,CAACU;YAC3B,IAAIV,CAAAA,wBAAAA,KAAMG,KAAK,aAAYf,OAAO;gBAChC,OAAO,aACFY;oBACHG,OAAOjB,WAAWc,KAAKG,KAAK;;YAEhC;YACA,OAAOH;QACT;IACF;AACF,EAAC;AAED,OAAO,MAAMY,iBAAiB,CAC5BZ,MAKAU;IAEA,OAAOnB,OAAOC,kBAAkBQ,OAAOU;AACzC,EAAC;AAED,eAAeE,eAAc"}