@noy-db/yjs 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -42,13 +42,13 @@ module.exports = __toCommonJS(index_exports);
42
42
  var Y = __toESM(require("yjs"), 1);
43
43
  var YjsCollection = class {
44
44
  /** @internal — use `yjsCollection()` factory instead. */
45
- constructor(compartment, name, opts) {
46
- this.compartment = compartment;
45
+ constructor(vault, name, opts) {
46
+ this.vault = vault;
47
47
  this.name = name;
48
48
  this.yFields = opts.yFields;
49
- this.coll = compartment.collection(name, { crdt: "yjs" });
49
+ this.coll = vault.collection(name, { crdt: "yjs" });
50
50
  }
51
- compartment;
51
+ vault;
52
52
  name;
53
53
  coll;
54
54
  yFields;
@@ -132,8 +132,8 @@ function base64ToUint8Array(base64) {
132
132
  }
133
133
  return bytes;
134
134
  }
135
- function yjsCollection(compartment, name, opts) {
136
- return new YjsCollection(compartment, name, opts);
135
+ function yjsCollection(vault, name, opts) {
136
+ return new YjsCollection(vault, name, opts);
137
137
  }
138
138
 
139
139
  // src/descriptors.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/yjs-collection.ts","../src/descriptors.ts"],"sourcesContent":["/**\n * @noy-db/yjs — Yjs Y.Doc interop for noy-db.\n *\n * Enables collaborative rich-text editing with encrypted-at-rest Yjs state.\n * Requires peer dependencies: `@noy-db/core` and `yjs >= 13`.\n *\n * @example\n * ```ts\n * import { yjsCollection, yText } from '@noy-db/yjs'\n *\n * const notes = yjsCollection(comp, 'notes', {\n * yFields: { body: yText() },\n * })\n *\n * const doc = await notes.getYDoc('note-1')\n * doc.getText('body').insert(0, 'Hello world')\n * await notes.putYDoc('note-1', doc)\n * ```\n */\n\nexport { yjsCollection, YjsCollection } from './yjs-collection.js'\nexport type {\n YjsCollectionOptions,\n YjsSnapshot,\n} from './yjs-collection.js'\n\nexport { yText, yMap, yArray } from './descriptors.js'\nexport type {\n YFieldDescriptor,\n YTextDescriptor,\n YMapDescriptor,\n YArrayDescriptor,\n} from './descriptors.js'\n","/**\n * YjsCollection — wraps a noy-db Collection<string> (crdt: 'yjs') with\n * Y.Doc-aware `getYDoc` and `putYDoc` methods.\n *\n * The encrypted envelope stores base64(Y.encodeStateAsUpdate(ydoc)) in `_data`.\n * `collection.get(id)` returns this raw base64 string. `getYDoc(id)` decodes\n * it into a Y.Doc and applies any `yFields` initialisation.\n *\n * v0.9 #136\n */\n\nimport * as Y from 'yjs'\nimport type { Compartment } from '@noy-db/core'\nimport type { YFieldDescriptor } from './descriptors.js'\n\n/** A resolved snapshot of a Yjs-backed record. Field values depend on yFields descriptors. */\nexport type YjsSnapshot<YF extends Record<string, YFieldDescriptor>> = {\n [K in keyof YF]: YF[K] extends { _yjsType: 'Y.Text' }\n ? Y.Text\n : YF[K] extends { _yjsType: 'Y.Map' }\n ? Y.Map<unknown>\n : Y.Array<unknown>\n}\n\n/** Options for creating a YjsCollection. */\nexport interface YjsCollectionOptions<YF extends Record<string, YFieldDescriptor>> {\n /** The field descriptors — tells YjsCollection which Y.* types to initialise. */\n yFields: YF\n}\n\n/**\n * A YjsCollection wraps a noy-db `crdt: 'yjs'` collection and exposes\n * `getYDoc(id)` and `putYDoc(id, ydoc)` instead of the raw `get`/`put` API.\n *\n * Construct via `yjsCollection(compartment, name, opts)`.\n */\nexport class YjsCollection<YF extends Record<string, YFieldDescriptor>> {\n private readonly coll: ReturnType<Compartment['collection']>\n private readonly yFields: YF\n\n /** @internal — use `yjsCollection()` factory instead. */\n constructor(\n private readonly compartment: Compartment,\n private readonly name: string,\n opts: YjsCollectionOptions<YF>,\n ) {\n this.yFields = opts.yFields\n // Collection<string> with crdt: 'yjs' — T = string (the base64 update blob)\n this.coll = compartment.collection<string>(name, { crdt: 'yjs' })\n }\n\n /**\n * Get the Y.Doc for a record.\n *\n * If the record does not exist, returns a fresh empty Y.Doc with the declared\n * `yFields` initialised (Y.Text / Y.Map / Y.Array as declared).\n *\n * If the record exists, the stored Yjs update is applied to the returned doc.\n */\n async getYDoc(id: string): Promise<Y.Doc> {\n const doc = new Y.Doc()\n this.initFields(doc)\n\n const base64Update = await this.coll.get(id) as string | null\n if (base64Update) {\n const bytes = base64ToUint8Array(base64Update)\n Y.applyUpdate(doc, bytes)\n }\n\n return doc\n }\n\n /**\n * Persist a Y.Doc by encoding its state as a Yjs update and storing it\n * as the encrypted envelope payload.\n */\n async putYDoc(id: string, doc: Y.Doc): Promise<void> {\n const update = Y.encodeStateAsUpdate(doc)\n const base64 = uint8ArrayToBase64(update)\n await this.coll.put(id, base64)\n }\n\n /**\n * Merge a Yjs update into an existing record.\n * Reads the current doc, applies the update, then persists the merged state.\n */\n async applyUpdate(id: string, update: Uint8Array): Promise<void> {\n const doc = await this.getYDoc(id)\n Y.applyUpdate(doc, update)\n await this.putYDoc(id, doc)\n }\n\n /**\n * Delete the record.\n */\n async delete(id: string): Promise<void> {\n await this.coll.delete(id)\n }\n\n /**\n * Check whether a record exists.\n */\n async has(id: string): Promise<boolean> {\n return (await this.coll.get(id)) !== null\n }\n\n // ─── Private ────────────────────────────────────────────────────────\n\n private initFields(doc: Y.Doc): void {\n for (const [fieldName, descriptor] of Object.entries(this.yFields)) {\n switch (descriptor._yjsType) {\n case 'Y.Text':\n doc.getText(fieldName)\n break\n case 'Y.Map':\n doc.getMap(fieldName)\n break\n case 'Y.Array':\n doc.getArray(fieldName)\n break\n }\n }\n }\n}\n\n// ─── Base64 helpers ───────────────────────────────────────────────────────────\n\nfunction uint8ArrayToBase64(bytes: Uint8Array): string {\n let binary = ''\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]!)\n }\n return btoa(binary)\n}\n\nfunction base64ToUint8Array(base64: string): Uint8Array {\n const binary = atob(base64)\n const bytes = new Uint8Array(binary.length)\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i)\n }\n return bytes\n}\n\n// ─── Factory function ─────────────────────────────────────────────────────────\n\n/**\n * Create a `YjsCollection` for a compartment.\n *\n * @param compartment An opened NOYDB compartment.\n * @param name Collection name (must not start with `_`).\n * @param opts Field descriptors (`yFields`) and optional collection settings.\n *\n * @example\n * ```ts\n * import { yjsCollection, yText } from '@noy-db/yjs'\n *\n * const notes = yjsCollection(comp, 'notes', {\n * yFields: { body: yText() },\n * })\n *\n * const doc = await notes.getYDoc('note-1')\n * doc.getText('body').insert(0, 'Hello world')\n * await notes.putYDoc('note-1', doc)\n * ```\n */\nexport function yjsCollection<YF extends Record<string, YFieldDescriptor>>(\n compartment: Compartment,\n name: string,\n opts: YjsCollectionOptions<YF>,\n): YjsCollection<YF> {\n return new YjsCollection(compartment, name, opts)\n}\n","/**\n * Field descriptors for Yjs-backed fields in @noy-db/yjs.\n * Mirrors the dictKey / i18nText descriptor pattern from @noy-db/core.\n */\n\n/** Descriptor for a Y.Text field (rich text, TipTap/ProseMirror compatible). */\nexport interface YTextDescriptor {\n readonly _yjsType: 'Y.Text'\n}\n\n/** Descriptor for a Y.Map<string> field. */\nexport interface YMapDescriptor {\n readonly _yjsType: 'Y.Map'\n}\n\n/** Descriptor for a Y.Array field. */\nexport interface YArrayDescriptor {\n readonly _yjsType: 'Y.Array'\n}\n\nexport type YFieldDescriptor = YTextDescriptor | YMapDescriptor | YArrayDescriptor\n\n/** Declare a Y.Text field (rich text). */\nexport function yText(): YTextDescriptor {\n return { _yjsType: 'Y.Text' }\n}\n\n/** Declare a Y.Map field. */\nexport function yMap(): YMapDescriptor {\n return { _yjsType: 'Y.Map' }\n}\n\n/** Declare a Y.Array field. */\nexport function yArray(): YArrayDescriptor {\n return { _yjsType: 'Y.Array' }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWA,QAAmB;AAyBZ,IAAM,gBAAN,MAAiE;AAAA;AAAA,EAKtE,YACmB,aACA,MACjB,MACA;AAH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H,cAAI,OAAO,SAAS;AACpB;AAAA,QACF,KAAK;AACH,cAAI,SAAS,SAAS;AACtB;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AACF;AAIA,SAAS,mBAAmB,OAA2B;AACrD,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,cAAU,OAAO,aAAa,MAAM,CAAC,CAAE;AAAA,EACzC;AACA,SAAO,KAAK,MAAM;AACpB;AAEA,SAAS,mBAAmB,QAA4B;AACtD,QAAM,SAAS,KAAK,MAAM;AAC1B,QAAM,QAAQ,IAAI,WAAW,OAAO,MAAM;AAC1C,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,UAAM,CAAC,IAAI,OAAO,WAAW,CAAC;AAAA,EAChC;AACA,SAAO;AACT;AAwBO,SAAS,cACd,aACA,MACA,MACmB;AACnB,SAAO,IAAI,cAAc,aAAa,MAAM,IAAI;AAClD;;;ACrJO,SAAS,QAAyB;AACvC,SAAO,EAAE,UAAU,SAAS;AAC9B;AAGO,SAAS,OAAuB;AACrC,SAAO,EAAE,UAAU,QAAQ;AAC7B;AAGO,SAAS,SAA2B;AACzC,SAAO,EAAE,UAAU,UAAU;AAC/B;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/yjs-collection.ts","../src/descriptors.ts"],"sourcesContent":["/**\n * @noy-db/yjs — Yjs Y.Doc interop for noy-db.\n *\n * Enables collaborative rich-text editing with encrypted-at-rest Yjs state.\n * Requires peer dependencies: `@noy-db/core` and `yjs >= 13`.\n *\n * @example\n * ```ts\n * import { yjsCollection, yText } from '@noy-db/yjs'\n *\n * const notes = yjsCollection(comp, 'notes', {\n * yFields: { body: yText() },\n * })\n *\n * const doc = await notes.getYDoc('note-1')\n * doc.getText('body').insert(0, 'Hello world')\n * await notes.putYDoc('note-1', doc)\n * ```\n */\n\nexport { yjsCollection, YjsCollection } from './yjs-collection.js'\nexport type {\n YjsCollectionOptions,\n YjsSnapshot,\n} from './yjs-collection.js'\n\nexport { yText, yMap, yArray } from './descriptors.js'\nexport type {\n YFieldDescriptor,\n YTextDescriptor,\n YMapDescriptor,\n YArrayDescriptor,\n} from './descriptors.js'\n","/**\n * YjsCollection — wraps a noy-db Collection<string> (crdt: 'yjs') with\n * Y.Doc-aware `getYDoc` and `putYDoc` methods.\n *\n * The encrypted envelope stores base64(Y.encodeStateAsUpdate(ydoc)) in `_data`.\n * `collection.get(id)` returns this raw base64 string. `getYDoc(id)` decodes\n * it into a Y.Doc and applies any `yFields` initialisation.\n *\n * v0.9 #136\n */\n\nimport * as Y from 'yjs'\nimport type { Vault } from '@noy-db/core'\nimport type { YFieldDescriptor } from './descriptors.js'\n\n/** A resolved snapshot of a Yjs-backed record. Field values depend on yFields descriptors. */\nexport type YjsSnapshot<YF extends Record<string, YFieldDescriptor>> = {\n [K in keyof YF]: YF[K] extends { _yjsType: 'Y.Text' }\n ? Y.Text\n : YF[K] extends { _yjsType: 'Y.Map' }\n ? Y.Map<unknown>\n : Y.Array<unknown>\n}\n\n/** Options for creating a YjsCollection. */\nexport interface YjsCollectionOptions<YF extends Record<string, YFieldDescriptor>> {\n /** The field descriptors — tells YjsCollection which Y.* types to initialise. */\n yFields: YF\n}\n\n/**\n * A YjsCollection wraps a noy-db `crdt: 'yjs'` collection and exposes\n * `getYDoc(id)` and `putYDoc(id, ydoc)` instead of the raw `get`/`put` API.\n *\n * Construct via `yjsCollection(vault, name, opts)`.\n */\nexport class YjsCollection<YF extends Record<string, YFieldDescriptor>> {\n private readonly coll: ReturnType<Vault['collection']>\n private readonly yFields: YF\n\n /** @internal — use `yjsCollection()` factory instead. */\n constructor(\n private readonly vault: Vault,\n private readonly name: string,\n opts: YjsCollectionOptions<YF>,\n ) {\n this.yFields = opts.yFields\n // Collection<string> with crdt: 'yjs' — T = string (the base64 update blob)\n this.coll = vault.collection<string>(name, { crdt: 'yjs' })\n }\n\n /**\n * Get the Y.Doc for a record.\n *\n * If the record does not exist, returns a fresh empty Y.Doc with the declared\n * `yFields` initialised (Y.Text / Y.Map / Y.Array as declared).\n *\n * If the record exists, the stored Yjs update is applied to the returned doc.\n */\n async getYDoc(id: string): Promise<Y.Doc> {\n const doc = new Y.Doc()\n this.initFields(doc)\n\n const base64Update = await this.coll.get(id) as string | null\n if (base64Update) {\n const bytes = base64ToUint8Array(base64Update)\n Y.applyUpdate(doc, bytes)\n }\n\n return doc\n }\n\n /**\n * Persist a Y.Doc by encoding its state as a Yjs update and storing it\n * as the encrypted envelope payload.\n */\n async putYDoc(id: string, doc: Y.Doc): Promise<void> {\n const update = Y.encodeStateAsUpdate(doc)\n const base64 = uint8ArrayToBase64(update)\n await this.coll.put(id, base64)\n }\n\n /**\n * Merge a Yjs update into an existing record.\n * Reads the current doc, applies the update, then persists the merged state.\n */\n async applyUpdate(id: string, update: Uint8Array): Promise<void> {\n const doc = await this.getYDoc(id)\n Y.applyUpdate(doc, update)\n await this.putYDoc(id, doc)\n }\n\n /**\n * Delete the record.\n */\n async delete(id: string): Promise<void> {\n await this.coll.delete(id)\n }\n\n /**\n * Check whether a record exists.\n */\n async has(id: string): Promise<boolean> {\n return (await this.coll.get(id)) !== null\n }\n\n // ─── Private ────────────────────────────────────────────────────────\n\n private initFields(doc: Y.Doc): void {\n for (const [fieldName, descriptor] of Object.entries(this.yFields)) {\n switch (descriptor._yjsType) {\n case 'Y.Text':\n doc.getText(fieldName)\n break\n case 'Y.Map':\n doc.getMap(fieldName)\n break\n case 'Y.Array':\n doc.getArray(fieldName)\n break\n }\n }\n }\n}\n\n// ─── Base64 helpers ───────────────────────────────────────────────────────────\n\nfunction uint8ArrayToBase64(bytes: Uint8Array): string {\n let binary = ''\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]!)\n }\n return btoa(binary)\n}\n\nfunction base64ToUint8Array(base64: string): Uint8Array {\n const binary = atob(base64)\n const bytes = new Uint8Array(binary.length)\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i)\n }\n return bytes\n}\n\n// ─── Factory function ─────────────────────────────────────────────────────────\n\n/**\n * Create a `YjsCollection` for a vault.\n *\n * @param vault An opened NOYDB vault.\n * @param name Collection name (must not start with `_`).\n * @param opts Field descriptors (`yFields`) and optional collection settings.\n *\n * @example\n * ```ts\n * import { yjsCollection, yText } from '@noy-db/yjs'\n *\n * const notes = yjsCollection(comp, 'notes', {\n * yFields: { body: yText() },\n * })\n *\n * const doc = await notes.getYDoc('note-1')\n * doc.getText('body').insert(0, 'Hello world')\n * await notes.putYDoc('note-1', doc)\n * ```\n */\nexport function yjsCollection<YF extends Record<string, YFieldDescriptor>>(\n vault: Vault,\n name: string,\n opts: YjsCollectionOptions<YF>,\n): YjsCollection<YF> {\n return new YjsCollection(vault, name, opts)\n}\n","/**\n * Field descriptors for Yjs-backed fields in @noy-db/yjs.\n * Mirrors the dictKey / i18nText descriptor pattern from @noy-db/core.\n */\n\n/** Descriptor for a Y.Text field (rich text, TipTap/ProseMirror compatible). */\nexport interface YTextDescriptor {\n readonly _yjsType: 'Y.Text'\n}\n\n/** Descriptor for a Y.Map<string> field. */\nexport interface YMapDescriptor {\n readonly _yjsType: 'Y.Map'\n}\n\n/** Descriptor for a Y.Array field. */\nexport interface YArrayDescriptor {\n readonly _yjsType: 'Y.Array'\n}\n\nexport type YFieldDescriptor = YTextDescriptor | YMapDescriptor | YArrayDescriptor\n\n/** Declare a Y.Text field (rich text). */\nexport function yText(): YTextDescriptor {\n return { _yjsType: 'Y.Text' }\n}\n\n/** Declare a Y.Map field. */\nexport function yMap(): YMapDescriptor {\n return { _yjsType: 'Y.Map' }\n}\n\n/** Declare a Y.Array field. */\nexport function yArray(): YArrayDescriptor {\n return { _yjsType: 'Y.Array' }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWA,QAAmB;AAyBZ,IAAM,gBAAN,MAAiE;AAAA;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,QAAQ,SAAS;AACrB;AAAA,QACF,KAAK;AACH,cAAI,OAAO,SAAS;AACpB;AAAA,QACF,KAAK;AACH,cAAI,SAAS,SAAS;AACtB;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AACF;AAIA,SAAS,mBAAmB,OAA2B;AACrD,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,cAAU,OAAO,aAAa,MAAM,CAAC,CAAE;AAAA,EACzC;AACA,SAAO,KAAK,MAAM;AACpB;AAEA,SAAS,mBAAmB,QAA4B;AACtD,QAAM,SAAS,KAAK,MAAM;AAC1B,QAAM,QAAQ,IAAI,WAAW,OAAO,MAAM;AAC1C,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,UAAM,CAAC,IAAI,OAAO,WAAW,CAAC;AAAA,EAChC;AACA,SAAO;AACT;AAwBO,SAAS,cACd,OACA,MACA,MACmB;AACnB,SAAO,IAAI,cAAc,OAAO,MAAM,IAAI;AAC5C;;;ACrJO,SAAS,QAAyB;AACvC,SAAO,EAAE,UAAU,SAAS;AAC9B;AAGO,SAAS,OAAuB;AACrC,SAAO,EAAE,UAAU,QAAQ;AAC7B;AAGO,SAAS,SAA2B;AACzC,SAAO,EAAE,UAAU,UAAU;AAC/B;","names":[]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as Y from 'yjs';
2
- import { Compartment } from '@noy-db/core';
2
+ import { Vault } from '@noy-db/core';
3
3
 
4
4
  /**
5
5
  * Field descriptors for Yjs-backed fields in @noy-db/yjs.
@@ -53,15 +53,15 @@ interface YjsCollectionOptions<YF extends Record<string, YFieldDescriptor>> {
53
53
  * A YjsCollection wraps a noy-db `crdt: 'yjs'` collection and exposes
54
54
  * `getYDoc(id)` and `putYDoc(id, ydoc)` instead of the raw `get`/`put` API.
55
55
  *
56
- * Construct via `yjsCollection(compartment, name, opts)`.
56
+ * Construct via `yjsCollection(vault, name, opts)`.
57
57
  */
58
58
  declare class YjsCollection<YF extends Record<string, YFieldDescriptor>> {
59
- private readonly compartment;
59
+ private readonly vault;
60
60
  private readonly name;
61
61
  private readonly coll;
62
62
  private readonly yFields;
63
63
  /** @internal — use `yjsCollection()` factory instead. */
64
- constructor(compartment: Compartment, name: string, opts: YjsCollectionOptions<YF>);
64
+ constructor(vault: Vault, name: string, opts: YjsCollectionOptions<YF>);
65
65
  /**
66
66
  * Get the Y.Doc for a record.
67
67
  *
@@ -92,9 +92,9 @@ declare class YjsCollection<YF extends Record<string, YFieldDescriptor>> {
92
92
  private initFields;
93
93
  }
94
94
  /**
95
- * Create a `YjsCollection` for a compartment.
95
+ * Create a `YjsCollection` for a vault.
96
96
  *
97
- * @param compartment An opened NOYDB compartment.
97
+ * @param vault An opened NOYDB vault.
98
98
  * @param name Collection name (must not start with `_`).
99
99
  * @param opts Field descriptors (`yFields`) and optional collection settings.
100
100
  *
@@ -111,6 +111,6 @@ declare class YjsCollection<YF extends Record<string, YFieldDescriptor>> {
111
111
  * await notes.putYDoc('note-1', doc)
112
112
  * ```
113
113
  */
114
- declare function yjsCollection<YF extends Record<string, YFieldDescriptor>>(compartment: Compartment, name: string, opts: YjsCollectionOptions<YF>): YjsCollection<YF>;
114
+ declare function yjsCollection<YF extends Record<string, YFieldDescriptor>>(vault: Vault, name: string, opts: YjsCollectionOptions<YF>): YjsCollection<YF>;
115
115
 
116
116
  export { type YArrayDescriptor, type YFieldDescriptor, type YMapDescriptor, type YTextDescriptor, YjsCollection, type YjsCollectionOptions, type YjsSnapshot, yArray, yMap, yText, yjsCollection };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as Y from 'yjs';
2
- import { Compartment } from '@noy-db/core';
2
+ import { Vault } from '@noy-db/core';
3
3
 
4
4
  /**
5
5
  * Field descriptors for Yjs-backed fields in @noy-db/yjs.
@@ -53,15 +53,15 @@ interface YjsCollectionOptions<YF extends Record<string, YFieldDescriptor>> {
53
53
  * A YjsCollection wraps a noy-db `crdt: 'yjs'` collection and exposes
54
54
  * `getYDoc(id)` and `putYDoc(id, ydoc)` instead of the raw `get`/`put` API.
55
55
  *
56
- * Construct via `yjsCollection(compartment, name, opts)`.
56
+ * Construct via `yjsCollection(vault, name, opts)`.
57
57
  */
58
58
  declare class YjsCollection<YF extends Record<string, YFieldDescriptor>> {
59
- private readonly compartment;
59
+ private readonly vault;
60
60
  private readonly name;
61
61
  private readonly coll;
62
62
  private readonly yFields;
63
63
  /** @internal — use `yjsCollection()` factory instead. */
64
- constructor(compartment: Compartment, name: string, opts: YjsCollectionOptions<YF>);
64
+ constructor(vault: Vault, name: string, opts: YjsCollectionOptions<YF>);
65
65
  /**
66
66
  * Get the Y.Doc for a record.
67
67
  *
@@ -92,9 +92,9 @@ declare class YjsCollection<YF extends Record<string, YFieldDescriptor>> {
92
92
  private initFields;
93
93
  }
94
94
  /**
95
- * Create a `YjsCollection` for a compartment.
95
+ * Create a `YjsCollection` for a vault.
96
96
  *
97
- * @param compartment An opened NOYDB compartment.
97
+ * @param vault An opened NOYDB vault.
98
98
  * @param name Collection name (must not start with `_`).
99
99
  * @param opts Field descriptors (`yFields`) and optional collection settings.
100
100
  *
@@ -111,6 +111,6 @@ declare class YjsCollection<YF extends Record<string, YFieldDescriptor>> {
111
111
  * await notes.putYDoc('note-1', doc)
112
112
  * ```
113
113
  */
114
- declare function yjsCollection<YF extends Record<string, YFieldDescriptor>>(compartment: Compartment, name: string, opts: YjsCollectionOptions<YF>): YjsCollection<YF>;
114
+ declare function yjsCollection<YF extends Record<string, YFieldDescriptor>>(vault: Vault, name: string, opts: YjsCollectionOptions<YF>): YjsCollection<YF>;
115
115
 
116
116
  export { type YArrayDescriptor, type YFieldDescriptor, type YMapDescriptor, type YTextDescriptor, YjsCollection, type YjsCollectionOptions, type YjsSnapshot, yArray, yMap, yText, yjsCollection };
package/dist/index.js CHANGED
@@ -2,13 +2,13 @@
2
2
  import * as Y from "yjs";
3
3
  var YjsCollection = class {
4
4
  /** @internal — use `yjsCollection()` factory instead. */
5
- constructor(compartment, name, opts) {
6
- this.compartment = compartment;
5
+ constructor(vault, name, opts) {
6
+ this.vault = vault;
7
7
  this.name = name;
8
8
  this.yFields = opts.yFields;
9
- this.coll = compartment.collection(name, { crdt: "yjs" });
9
+ this.coll = vault.collection(name, { crdt: "yjs" });
10
10
  }
11
- compartment;
11
+ vault;
12
12
  name;
13
13
  coll;
14
14
  yFields;
@@ -92,8 +92,8 @@ function base64ToUint8Array(base64) {
92
92
  }
93
93
  return bytes;
94
94
  }
95
- function yjsCollection(compartment, name, opts) {
96
- return new YjsCollection(compartment, name, opts);
95
+ function yjsCollection(vault, name, opts) {
96
+ return new YjsCollection(vault, name, opts);
97
97
  }
98
98
 
99
99
  // src/descriptors.ts
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/yjs-collection.ts","../src/descriptors.ts"],"sourcesContent":["/**\n * YjsCollection — wraps a noy-db Collection<string> (crdt: 'yjs') with\n * Y.Doc-aware `getYDoc` and `putYDoc` methods.\n *\n * The encrypted envelope stores base64(Y.encodeStateAsUpdate(ydoc)) in `_data`.\n * `collection.get(id)` returns this raw base64 string. `getYDoc(id)` decodes\n * it into a Y.Doc and applies any `yFields` initialisation.\n *\n * v0.9 #136\n */\n\nimport * as Y from 'yjs'\nimport type { Compartment } from '@noy-db/core'\nimport type { YFieldDescriptor } from './descriptors.js'\n\n/** A resolved snapshot of a Yjs-backed record. Field values depend on yFields descriptors. */\nexport type YjsSnapshot<YF extends Record<string, YFieldDescriptor>> = {\n [K in keyof YF]: YF[K] extends { _yjsType: 'Y.Text' }\n ? Y.Text\n : YF[K] extends { _yjsType: 'Y.Map' }\n ? Y.Map<unknown>\n : Y.Array<unknown>\n}\n\n/** Options for creating a YjsCollection. */\nexport interface YjsCollectionOptions<YF extends Record<string, YFieldDescriptor>> {\n /** The field descriptors — tells YjsCollection which Y.* types to initialise. */\n yFields: YF\n}\n\n/**\n * A YjsCollection wraps a noy-db `crdt: 'yjs'` collection and exposes\n * `getYDoc(id)` and `putYDoc(id, ydoc)` instead of the raw `get`/`put` API.\n *\n * Construct via `yjsCollection(compartment, name, opts)`.\n */\nexport class YjsCollection<YF extends Record<string, YFieldDescriptor>> {\n private readonly coll: ReturnType<Compartment['collection']>\n private readonly yFields: YF\n\n /** @internal — use `yjsCollection()` factory instead. */\n constructor(\n private readonly compartment: Compartment,\n private readonly name: string,\n opts: YjsCollectionOptions<YF>,\n ) {\n this.yFields = opts.yFields\n // Collection<string> with crdt: 'yjs' — T = string (the base64 update blob)\n this.coll = compartment.collection<string>(name, { crdt: 'yjs' })\n }\n\n /**\n * Get the Y.Doc for a record.\n *\n * If the record does not exist, returns a fresh empty Y.Doc with the declared\n * `yFields` initialised (Y.Text / Y.Map / Y.Array as declared).\n *\n * If the record exists, the stored Yjs update is applied to the returned doc.\n */\n async getYDoc(id: string): Promise<Y.Doc> {\n const doc = new Y.Doc()\n this.initFields(doc)\n\n const base64Update = await this.coll.get(id) as string | null\n if (base64Update) {\n const bytes = base64ToUint8Array(base64Update)\n Y.applyUpdate(doc, bytes)\n }\n\n return doc\n }\n\n /**\n * Persist a Y.Doc by encoding its state as a Yjs update and storing it\n * as the encrypted envelope payload.\n */\n async putYDoc(id: string, doc: Y.Doc): Promise<void> {\n const update = Y.encodeStateAsUpdate(doc)\n const base64 = uint8ArrayToBase64(update)\n await this.coll.put(id, base64)\n }\n\n /**\n * Merge a Yjs update into an existing record.\n * Reads the current doc, applies the update, then persists the merged state.\n */\n async applyUpdate(id: string, update: Uint8Array): Promise<void> {\n const doc = await this.getYDoc(id)\n Y.applyUpdate(doc, update)\n await this.putYDoc(id, doc)\n }\n\n /**\n * Delete the record.\n */\n async delete(id: string): Promise<void> {\n await this.coll.delete(id)\n }\n\n /**\n * Check whether a record exists.\n */\n async has(id: string): Promise<boolean> {\n return (await this.coll.get(id)) !== null\n }\n\n // ─── Private ────────────────────────────────────────────────────────\n\n private initFields(doc: Y.Doc): void {\n for (const [fieldName, descriptor] of Object.entries(this.yFields)) {\n switch (descriptor._yjsType) {\n case 'Y.Text':\n doc.getText(fieldName)\n break\n case 'Y.Map':\n doc.getMap(fieldName)\n break\n case 'Y.Array':\n doc.getArray(fieldName)\n break\n }\n }\n }\n}\n\n// ─── Base64 helpers ───────────────────────────────────────────────────────────\n\nfunction uint8ArrayToBase64(bytes: Uint8Array): string {\n let binary = ''\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]!)\n }\n return btoa(binary)\n}\n\nfunction base64ToUint8Array(base64: string): Uint8Array {\n const binary = atob(base64)\n const bytes = new Uint8Array(binary.length)\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i)\n }\n return bytes\n}\n\n// ─── Factory function ─────────────────────────────────────────────────────────\n\n/**\n * Create a `YjsCollection` for a compartment.\n *\n * @param compartment An opened NOYDB compartment.\n * @param name Collection name (must not start with `_`).\n * @param opts Field descriptors (`yFields`) and optional collection settings.\n *\n * @example\n * ```ts\n * import { yjsCollection, yText } from '@noy-db/yjs'\n *\n * const notes = yjsCollection(comp, 'notes', {\n * yFields: { body: yText() },\n * })\n *\n * const doc = await notes.getYDoc('note-1')\n * doc.getText('body').insert(0, 'Hello world')\n * await notes.putYDoc('note-1', doc)\n * ```\n */\nexport function yjsCollection<YF extends Record<string, YFieldDescriptor>>(\n compartment: Compartment,\n name: string,\n opts: YjsCollectionOptions<YF>,\n): YjsCollection<YF> {\n return new YjsCollection(compartment, name, opts)\n}\n","/**\n * Field descriptors for Yjs-backed fields in @noy-db/yjs.\n * Mirrors the dictKey / i18nText descriptor pattern from @noy-db/core.\n */\n\n/** Descriptor for a Y.Text field (rich text, TipTap/ProseMirror compatible). */\nexport interface YTextDescriptor {\n readonly _yjsType: 'Y.Text'\n}\n\n/** Descriptor for a Y.Map<string> field. */\nexport interface YMapDescriptor {\n readonly _yjsType: 'Y.Map'\n}\n\n/** Descriptor for a Y.Array field. */\nexport interface YArrayDescriptor {\n readonly _yjsType: 'Y.Array'\n}\n\nexport type YFieldDescriptor = YTextDescriptor | YMapDescriptor | YArrayDescriptor\n\n/** Declare a Y.Text field (rich text). */\nexport function yText(): YTextDescriptor {\n return { _yjsType: 'Y.Text' }\n}\n\n/** Declare a Y.Map field. */\nexport function yMap(): YMapDescriptor {\n return { _yjsType: 'Y.Map' }\n}\n\n/** Declare a Y.Array field. */\nexport function yArray(): YArrayDescriptor {\n return { _yjsType: 'Y.Array' }\n}\n"],"mappings":";AAWA,YAAY,OAAO;AAyBZ,IAAM,gBAAN,MAAiE;AAAA;AAAA,EAKtE,YACmB,aACA,MACjB,MACA;AAHiB;AACA;AAGjB,SAAK,UAAU,KAAK;AAEpB,SAAK,OAAO,YAAY,WAAmB,MAAM,EAAE,MAAM,MAAM,CAAC;AAAA,EAClE;AAAA,EAPmB;AAAA,EACA;AAAA,EANF;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBjB,MAAM,QAAQ,IAA4B;AACxC,UAAM,MAAM,IAAM,MAAI;AACtB,SAAK,WAAW,GAAG;AAEnB,UAAM,eAAe,MAAM,KAAK,KAAK,IAAI,EAAE;AAC3C,QAAI,cAAc;AAChB,YAAM,QAAQ,mBAAmB,YAAY;AAC7C,MAAE,cAAY,KAAK,KAAK;AAAA,IAC1B;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,QAAQ,IAAY,KAA2B;AACnD,UAAM,SAAW,sBAAoB,GAAG;AACxC,UAAM,SAAS,mBAAmB,MAAM;AACxC,UAAM,KAAK,KAAK,IAAI,IAAI,MAAM;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,YAAY,IAAY,QAAmC;AAC/D,UAAM,MAAM,MAAM,KAAK,QAAQ,EAAE;AACjC,IAAE,cAAY,KAAK,MAAM;AACzB,UAAM,KAAK,QAAQ,IAAI,GAAG;AAAA,E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"sourcesContent":["/**\n * YjsCollection — wraps a noy-db Collection<string> (crdt: 'yjs') with\n * Y.Doc-aware `getYDoc` and `putYDoc` methods.\n *\n * The encrypted envelope stores base64(Y.encodeStateAsUpdate(ydoc)) in `_data`.\n * `collection.get(id)` returns this raw base64 string. `getYDoc(id)` decodes\n * it into a Y.Doc and applies any `yFields` initialisation.\n *\n * v0.9 #136\n */\n\nimport * as Y from 'yjs'\nimport type { Vault } from '@noy-db/core'\nimport type { YFieldDescriptor } from './descriptors.js'\n\n/** A resolved snapshot of a Yjs-backed record. Field values depend on yFields descriptors. */\nexport type YjsSnapshot<YF extends Record<string, YFieldDescriptor>> = {\n [K in keyof YF]: YF[K] extends { _yjsType: 'Y.Text' }\n ? Y.Text\n : YF[K] extends { _yjsType: 'Y.Map' }\n ? Y.Map<unknown>\n : Y.Array<unknown>\n}\n\n/** Options for creating a YjsCollection. */\nexport interface YjsCollectionOptions<YF extends Record<string, YFieldDescriptor>> {\n /** The field descriptors — tells YjsCollection which Y.* types to initialise. */\n yFields: YF\n}\n\n/**\n * A YjsCollection wraps a noy-db `crdt: 'yjs'` collection and exposes\n * `getYDoc(id)` and `putYDoc(id, ydoc)` instead of the raw `get`/`put` API.\n *\n * Construct via `yjsCollection(vault, name, opts)`.\n */\nexport class YjsCollection<YF extends Record<string, YFieldDescriptor>> {\n private readonly coll: ReturnType<Vault['collection']>\n private readonly yFields: YF\n\n /** @internal — use `yjsCollection()` factory instead. */\n constructor(\n private readonly vault: Vault,\n private readonly name: string,\n opts: YjsCollectionOptions<YF>,\n ) {\n this.yFields = opts.yFields\n // Collection<string> with crdt: 'yjs' — T = string (the base64 update blob)\n this.coll = vault.collection<string>(name, { crdt: 'yjs' })\n }\n\n /**\n * Get the Y.Doc for a record.\n *\n * If the record does not exist, returns a fresh empty Y.Doc with the declared\n * `yFields` initialised (Y.Text / Y.Map / Y.Array as declared).\n *\n * If the record exists, the stored Yjs update is applied to the returned doc.\n */\n async getYDoc(id: string): Promise<Y.Doc> {\n const doc = new Y.Doc()\n this.initFields(doc)\n\n const base64Update = await this.coll.get(id) as string | null\n if (base64Update) {\n const bytes = base64ToUint8Array(base64Update)\n Y.applyUpdate(doc, bytes)\n }\n\n return doc\n }\n\n /**\n * Persist a Y.Doc by encoding its state as a Yjs update and storing it\n * as the encrypted envelope payload.\n */\n async putYDoc(id: string, doc: Y.Doc): Promise<void> {\n const update = Y.encodeStateAsUpdate(doc)\n const base64 = uint8ArrayToBase64(update)\n await this.coll.put(id, base64)\n }\n\n /**\n * Merge a Yjs update into an existing record.\n * Reads the current doc, applies the update, then persists the merged state.\n */\n async applyUpdate(id: string, update: Uint8Array): Promise<void> {\n const doc = await this.getYDoc(id)\n Y.applyUpdate(doc, update)\n await this.putYDoc(id, doc)\n }\n\n /**\n * Delete the record.\n */\n async delete(id: string): Promise<void> {\n await this.coll.delete(id)\n }\n\n /**\n * Check whether a record exists.\n */\n async has(id: string): Promise<boolean> {\n return (await this.coll.get(id)) !== null\n }\n\n // ─── Private ────────────────────────────────────────────────────────\n\n private initFields(doc: Y.Doc): void {\n for (const [fieldName, descriptor] of Object.entries(this.yFields)) {\n switch (descriptor._yjsType) {\n case 'Y.Text':\n doc.getText(fieldName)\n break\n case 'Y.Map':\n doc.getMap(fieldName)\n break\n case 'Y.Array':\n doc.getArray(fieldName)\n break\n }\n }\n }\n}\n\n// ─── Base64 helpers ───────────────────────────────────────────────────────────\n\nfunction uint8ArrayToBase64(bytes: Uint8Array): string {\n let binary = ''\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]!)\n }\n return btoa(binary)\n}\n\nfunction base64ToUint8Array(base64: string): Uint8Array {\n const binary = atob(base64)\n const bytes = new Uint8Array(binary.length)\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i)\n }\n return bytes\n}\n\n// ─── Factory function ─────────────────────────────────────────────────────────\n\n/**\n * Create a `YjsCollection` for a vault.\n *\n * @param vault An opened NOYDB vault.\n * @param name Collection name (must not start with `_`).\n * @param opts Field descriptors (`yFields`) and optional collection settings.\n *\n * @example\n * ```ts\n * import { yjsCollection, yText } from '@noy-db/yjs'\n *\n * const notes = yjsCollection(comp, 'notes', {\n * yFields: { body: yText() },\n * })\n *\n * const doc = await notes.getYDoc('note-1')\n * doc.getText('body').insert(0, 'Hello world')\n * await notes.putYDoc('note-1', doc)\n * ```\n */\nexport function yjsCollection<YF extends Record<string, YFieldDescriptor>>(\n vault: Vault,\n name: string,\n opts: YjsCollectionOptions<YF>,\n): YjsCollection<YF> {\n return new YjsCollection(vault, name, opts)\n}\n","/**\n * Field descriptors for Yjs-backed fields in @noy-db/yjs.\n * Mirrors the dictKey / i18nText descriptor pattern from @noy-db/core.\n */\n\n/** Descriptor for a Y.Text field (rich text, TipTap/ProseMirror compatible). */\nexport interface YTextDescriptor {\n readonly _yjsType: 'Y.Text'\n}\n\n/** Descriptor for a Y.Map<string> field. */\nexport interface YMapDescriptor {\n readonly _yjsType: 'Y.Map'\n}\n\n/** Descriptor for a Y.Array field. */\nexport interface YArrayDescriptor {\n readonly _yjsType: 'Y.Array'\n}\n\nexport type YFieldDescriptor = YTextDescriptor | YMapDescriptor | YArrayDescriptor\n\n/** Declare a Y.Text field (rich text). */\nexport function yText(): YTextDescriptor {\n return { _yjsType: 'Y.Text' }\n}\n\n/** Declare a Y.Map field. */\nexport function yMap(): YMapDescriptor {\n return { _yjsType: 'Y.Map' }\n}\n\n/** Declare a Y.Array field. */\nexport function yArray(): YArrayDescriptor {\n return { _yjsType: 'Y.Array' }\n}\n"],"mappings":";AAWA,YAAY,OAAO;AAyBZ,IAAM,gBAAN,MAAiE;AAAA;AAAA,EAKtE,YACmB,OACA,MACjB,MACA;AAHiB;AACA;AAGjB,SAAK,UAAU,KAAK;AAEpB,SAAK,OAAO,MAAM,WAAmB,MAAM,EAAE,MAAM,MAAM,CAAC;AAAA,EAC5D;AAAA,EAPmB;AAAA,EACA;AAAA,EANF;AAAA,EACA;AAAA;AAAA;A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IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,cAAU,OAAO,aAAa,MAAM,CAAC,CAAE;AAAA,EACzC;AACA,SAAO,KAAK,MAAM;AACpB;AAEA,SAAS,mBAAmB,QAA4B;AACtD,QAAM,SAAS,KAAK,MAAM;AAC1B,QAAM,QAAQ,IAAI,WAAW,OAAO,MAAM;AAC1C,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,UAAM,CAAC,IAAI,OAAO,WAAW,CAAC;AAAA,EAChC;AACA,SAAO;AACT;AAwBO,SAAS,cACd,OACA,MACA,MACmB;AACnB,SAAO,IAAI,cAAc,OAAO,MAAM,IAAI;AAC5C;;;ACrJO,SAAS,QAAyB;AACvC,SAAO,EAAE,UAAU,SAAS;AAC9B;AAGO,SAAS,OAAuB;AACrC,SAAO,EAAE,UAAU,QAAQ;AAC7B;AAGO,SAAS,SAA2B;AACzC,SAAO,EAAE,UAAU,UAAU;AAC/B;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noy-db/yjs",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Yjs Y.Doc interop for noy-db — collaborative rich-text fields with encrypted-at-rest Yjs state",
5
5
  "license": "MIT",
6
6
  "author": "vLannaAi <vicio@lanna.ai>",
@@ -40,11 +40,11 @@
40
40
  },
41
41
  "peerDependencies": {
42
42
  "yjs": ">=13.0.0",
43
- "@noy-db/core": "0.9.0"
43
+ "@noy-db/core": "0.10.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "yjs": "^13.6.27",
47
- "@noy-db/core": "0.9.0"
47
+ "@noy-db/core": "0.10.0"
48
48
  },
49
49
  "keywords": [
50
50
  "noy-db",