@dxos/echo 0.11.1 → 1.0.0-next-bbabc02363f18d7643ea4160e3a7a7809870fd0d

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/lib/Tag.mjs CHANGED
@@ -7,10 +7,14 @@ import { foreignKeys, type } from "./Filter.mjs";
7
7
  import * as Schema from "effect/Schema";
8
8
  //#region src/Tag.ts
9
9
  var Tag_exports = /* @__PURE__ */ __exportAll({
10
+ CANONICAL_ORIGIN: () => CANONICAL_ORIGIN,
10
11
  Tag: () => Tag,
11
12
  createTagList: () => createTagList,
12
13
  findOrCreate: () => findOrCreate,
13
14
  findTagByLabel: () => findTagByLabel,
15
+ getOrigin: () => getOrigin,
16
+ isProviderTag: () => isProviderTag,
17
+ isUserTag: () => isUserTag,
14
18
  make: () => make,
15
19
  sortTags: () => sortTags
16
20
  });
@@ -19,6 +23,38 @@ var Tag = class extends makeObject(TagTypeDXN)(Schema.Struct({
19
23
  hue: Schema.optional(Schema.String)
20
24
  }).pipe(LabelAnnotation.set(["label"]), HiddenAnnotation.set(true))) {};
21
25
  var make = (props) => make$1(Tag, props);
26
+ /**
27
+ * Origin domain for DXOS's own canonical tags — provider-agnostic identities (starred, sent, …) that
28
+ * each provider maps its own vocabulary onto, so a Gmail star, a JMAP `$flagged` keyword and a
29
+ * locally-toggled star all resolve to the same {@link Tag}.
30
+ */
31
+ var CANONICAL_ORIGIN = "org.dxos.tag";
32
+ /**
33
+ * The tag's origin domain, or `undefined` when the user created it. Says who owns the tag and
34
+ * therefore who may change it — see `Tag.md` §"Tag origin":
35
+ *
36
+ * - `undefined` — a user tag: rename, recolour, apply and remove are all the user's to do.
37
+ * - {@link CANONICAL_ORIGIN} — a canonical DXOS tag: applied and removed locally, but its label and
38
+ * hue are fixed (a provider may be mapping its own vocabulary onto it).
39
+ * - anything else — a foreign provider domain (e.g. `com.google.gmail`): read-only, since sync owns
40
+ * both the tag and which objects carry it.
41
+ *
42
+ * Read from the tag's first foreign key, which is where {@link findOrCreate} records it; a tag never
43
+ * carries more than one origin. Requires a live entity or snapshot — a spread copy (e.g. from
44
+ * {@link createTagList}) has no metadata and throws rather than reporting a false `undefined`.
45
+ */
46
+ var getOrigin = (tag) => getMeta(tag).keys[0]?.source;
47
+ /** Whether the user created this tag (and so may edit and apply it freely). See {@link getOrigin}. */
48
+ var isUserTag = (tag) => getOrigin(tag) === void 0;
49
+ /**
50
+ * Whether a foreign provider owns this tag, making it read-only in the app: it cannot be renamed,
51
+ * recoloured, or attached to / detached from an object by hand. Canonical DXOS tags are **not**
52
+ * provider tags — they stay locally toggleable. See {@link getOrigin}.
53
+ */
54
+ var isProviderTag = (tag) => {
55
+ const origin = getOrigin(tag);
56
+ return origin !== void 0 && origin !== "org.dxos.tag";
57
+ };
22
58
  var sortTags = ({ label: a }, { label: b }) => a.localeCompare(b);
23
59
  var createTagList = (tags) => Object.entries(tags).map(([id, tag]) => ({
24
60
  ...tag,
@@ -32,6 +68,21 @@ var findTagByLabel = (tags, name) => {
32
68
  } : void 0;
33
69
  };
34
70
  /**
71
+ * Finds a tag by a superseded key and rewrites that key to `key`, so the tag keeps its identity (and
72
+ * every reference to it) across a key-source rename. Returns `undefined` when none match.
73
+ */
74
+ var adoptLegacyKey = async (db, key, legacyKeys) => {
75
+ if (!legacyKeys?.length) return;
76
+ const [existing] = await db.query(foreignKeys(Tag, [...legacyKeys])).run();
77
+ if (!existing) return;
78
+ update(existing, (existing) => {
79
+ const keys = getMeta(existing).keys;
80
+ const index = keys.findIndex((candidate) => legacyKeys.some((legacy) => legacy.source === candidate.source && legacy.id === candidate.id));
81
+ if (index >= 0) keys.splice(index, 1, key);
82
+ });
83
+ return existing;
84
+ };
85
+ /**
35
86
  * Finds or creates a {@link Tag} object in the database.
36
87
  *
37
88
  * - With a foreign `key` (system/provider tags): matched by that key; the label is kept current on
@@ -39,12 +90,18 @@ var findTagByLabel = (tags, name) => {
39
90
  * identity is external or well-known.
40
91
  * - Without a key (user tags): matched by case-insensitive label among tags that carry **no**
41
92
  * foreign key, so it never collides with a keyed system/provider tag of the same label.
93
+ *
94
+ * `legacyKeys` lets a caller rename its key source without orphaning existing tags: when the primary
95
+ * key misses, they are tried in order and the first match is rewritten to `key` in place. Without it
96
+ * a rename silently creates a parallel tag on the next sync, while objects keep pointing at the old
97
+ * one. Drop the legacy key once the rename has shipped.
42
98
  */
43
99
  var findOrCreate = async (db, options) => {
44
- const { label, hue, key } = options;
100
+ const { label, hue, key, legacyKeys } = options;
45
101
  const withHue = hue ? { hue } : {};
46
102
  if (key) {
47
- const [existing] = await db.query(foreignKeys(Tag, [key])).run();
103
+ const [matched] = await db.query(foreignKeys(Tag, [key])).run();
104
+ const existing = matched ?? await adoptLegacyKey(db, key, legacyKeys);
48
105
  if (existing) {
49
106
  if (existing.label !== label || hue !== void 0 && existing.hue !== hue) update(existing, (existing) => {
50
107
  existing.label = label;
@@ -65,6 +122,6 @@ var findOrCreate = async (db, options) => {
65
122
  }));
66
123
  };
67
124
  //#endregion
68
- export { Tag, createTagList, findOrCreate, findTagByLabel, make, sortTags, Tag_exports as t };
125
+ export { CANONICAL_ORIGIN, Tag, createTagList, findOrCreate, findTagByLabel, getOrigin, isProviderTag, isUserTag, make, sortTags, Tag_exports as t };
69
126
 
70
127
  //# sourceMappingURL=Tag.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tag.mjs","names":[],"sources":["../../src/Tag.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport type { ForeignKey } from '@dxos/echo-protocol';\n\nimport type * as Database from './Database';\nimport * as Filter from './Filter';\nimport * as internal from './internal';\nimport * as Obj from './Obj';\nimport * as Type from './Type';\n\nexport class Tag extends Type.makeObject<Tag>(internal.TagTypeDXN)(\n Schema.Struct({\n label: Schema.String,\n hue: Schema.optional(Schema.String), // TODO(burdon): Color name?\n }).pipe(internal.LabelAnnotation.set(['label']), internal.HiddenAnnotation.set(true)),\n) {}\n\nexport const make = (props: Obj.MakeProps<typeof Tag>) => Obj.make(Tag, props);\n\nexport type Map = Record<string, Type.InstanceType<typeof Tag>>;\n\nexport const sortTags = ({ label: a }: Type.InstanceType<typeof Tag>, { label: b }: Type.InstanceType<typeof Tag>) =>\n a.localeCompare(b);\n\nexport const createTagList = (tags: Map): Type.InstanceType<typeof Tag>[] =>\n Object.entries(tags)\n .map(([id, tag]) => ({ ...tag, id }))\n .sort(sortTags);\n\nexport const findTagByLabel = (tags: Map | undefined, name: string): Type.InstanceType<typeof Tag> | undefined => {\n const entry = Object.entries(tags ?? {}).find(([_, tag]) => tag.label.toLowerCase() === name.toLowerCase());\n return entry ? { ...entry[1], id: entry[0] } : undefined;\n};\n\n/**\n * Finds or creates a {@link Tag} object in the database.\n *\n * - With a foreign `key` (system/provider tags): matched by that key; the label is kept current on\n * re-sync. Use a stable key (e.g. `{ source: 'google.com/gmail/label', id }`) for tags whose\n * identity is external or well-known.\n * - Without a key (user tags): matched by case-insensitive label among tags that carry **no**\n * foreign key, so it never collides with a keyed system/provider tag of the same label.\n */\nexport const findOrCreate = async (\n db: Pick<Database.Database, 'query' | 'add'>,\n options: { label: string; hue?: string; key?: ForeignKey },\n): Promise<Type.InstanceType<typeof Tag>> => {\n const { label, hue, key } = options;\n const withHue = hue ? { hue } : {};\n if (key) {\n const [existing] = await db.query(Filter.foreignKeys(Tag, [key])).run();\n if (existing) {\n // Keep label (and hue, when provided) current on re-sync. `hue` is only touched when supplied,\n // so a label-only re-sync (e.g. Gmail) doesn't wipe a user-set colour.\n if (existing.label !== label || (hue !== undefined && existing.hue !== hue)) {\n Obj.update(existing, (existing) => {\n existing.label = label;\n if (hue !== undefined) {\n existing.hue = hue;\n }\n });\n }\n return existing;\n }\n\n return db.add(Obj.make(Tag, { [Obj.Meta]: { keys: [key] }, label, ...withHue }));\n }\n\n const lowered = label.toLowerCase();\n const candidates = await db.query(Filter.type(Tag)).run();\n const existing = candidates.find(\n (tag) => tag.label.toLowerCase() === lowered && (Obj.getMeta(tag).keys ?? []).length === 0,\n );\n return existing ?? db.add(make({ label, ...withHue }));\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,IAAa,MAAb,cAAyB,WAAqB,UAAmB,CAAC,CAChE,OAAO,OAAO;CACZ,OAAO,OAAO;CACd,KAAK,OAAO,SAAS,OAAO,MAAM;AACpC,CAAC,CAAC,CAAC,KAAA,gBAA8B,IAAI,CAAC,OAAO,CAAC,GAAA,iBAA6B,IAAI,IAAI,CAAC,CACtF,CAAC,CAAC,CAAC;AAEH,IAAa,QAAQ,UAAqC,OAAS,KAAK,KAAK;AAI7E,IAAa,YAAY,EAAE,OAAO,KAAoC,EAAE,OAAO,QAC7E,EAAE,cAAc,CAAC;AAEnB,IAAa,iBAAiB,SAC5B,OAAO,QAAQ,IAAI,CAAA,CAChB,KAAK,CAAC,IAAI,UAAU;CAAE,GAAG;CAAK;AAAG,EAAE,CAAA,CACnC,KAAK,QAAQ;AAElB,IAAa,kBAAkB,MAAuB,SAA4D;CAChH,MAAM,QAAQ,OAAO,QAAQ,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,SAAS,IAAI,MAAM,YAAY,MAAM,KAAK,YAAY,CAAC;CAC1G,OAAO,QAAQ;EAAE,GAAG,MAAM;EAAI,IAAI,MAAM;CAAG,IAAI,KAAA;AACjD;;;;;;;;;;AAWA,IAAa,eAAe,OAC1B,IACA,YAC2C;CAC3C,MAAM,EAAE,OAAO,KAAK,QAAQ;CAC5B,MAAM,UAAU,MAAM,EAAE,IAAI,IAAI,CAAC;CACjC,IAAI,KAAK;EACP,MAAM,CAAC,YAAY,MAAM,GAAG,MAAM,YAAmB,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI;EACtE,IAAI,UAAU;GAGZ,IAAI,SAAS,UAAU,SAAU,QAAQ,KAAA,KAAa,SAAS,QAAQ,KACrE,OAAW,WAAW,aAAa;IACjC,SAAS,QAAQ;IACjB,IAAI,QAAQ,KAAA,GACV,SAAS,MAAM;GAEnB,CAAC;GAEH,OAAO;EACT;EAEA,OAAO,GAAG,IAAI,OAAS,KAAK;IAAG,OAAW,EAAE,MAAM,CAAC,GAAG,EAAE;GAAG;GAAO,GAAG;EAAQ,CAAC,CAAC;CACjF;CAEA,MAAM,UAAU,MAAM,YAAY;CAKlC,QAHiB,MADQ,GAAG,MAAM,KAAY,GAAG,CAAC,CAAC,CAAC,IAAI,EAAA,CAC5B,MACzB,QAAQ,IAAI,MAAM,YAAY,MAAM,YAAY,QAAY,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAA,CAAG,WAAW,CAEpF,KAAY,GAAG,IAAI,KAAK;EAAE;EAAO,GAAG;CAAQ,CAAC,CAAC;AACvD"}
1
+ {"version":3,"file":"Tag.mjs","names":[],"sources":["../../src/Tag.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport type { ForeignKey } from '@dxos/echo-protocol';\n\nimport type * as Database from './Database';\nimport * as Filter from './Filter';\nimport * as internal from './internal';\nimport * as Obj from './Obj';\nimport * as Type from './Type';\n\nexport class Tag extends Type.makeObject<Tag>(internal.TagTypeDXN)(\n Schema.Struct({\n label: Schema.String,\n hue: Schema.optional(Schema.String), // TODO(burdon): Color name?\n }).pipe(internal.LabelAnnotation.set(['label']), internal.HiddenAnnotation.set(true)),\n) {}\n\nexport const make = (props: Obj.MakeProps<typeof Tag>) => Obj.make(Tag, props);\n\nexport type Map = Record<string, Type.InstanceType<typeof Tag>>;\n\n/**\n * Origin domain for DXOS's own canonical tags — provider-agnostic identities (starred, sent, …) that\n * each provider maps its own vocabulary onto, so a Gmail star, a JMAP `$flagged` keyword and a\n * locally-toggled star all resolve to the same {@link Tag}.\n */\nexport const CANONICAL_ORIGIN = 'org.dxos.tag';\n\n/**\n * The tag's origin domain, or `undefined` when the user created it. Says who owns the tag and\n * therefore who may change it — see `Tag.md` §\"Tag origin\":\n *\n * - `undefined` — a user tag: rename, recolour, apply and remove are all the user's to do.\n * - {@link CANONICAL_ORIGIN} — a canonical DXOS tag: applied and removed locally, but its label and\n * hue are fixed (a provider may be mapping its own vocabulary onto it).\n * - anything else — a foreign provider domain (e.g. `com.google.gmail`): read-only, since sync owns\n * both the tag and which objects carry it.\n *\n * Read from the tag's first foreign key, which is where {@link findOrCreate} records it; a tag never\n * carries more than one origin. Requires a live entity or snapshot — a spread copy (e.g. from\n * {@link createTagList}) has no metadata and throws rather than reporting a false `undefined`.\n */\nexport const getOrigin = (tag: Type.InstanceType<typeof Tag> | Obj.Snapshot<Type.InstanceType<typeof Tag>>) =>\n Obj.getMeta(tag).keys[0]?.source;\n\n/** Whether the user created this tag (and so may edit and apply it freely). See {@link getOrigin}. */\nexport const isUserTag = (tag: Type.InstanceType<typeof Tag> | Obj.Snapshot<Type.InstanceType<typeof Tag>>) =>\n getOrigin(tag) === undefined;\n\n/**\n * Whether a foreign provider owns this tag, making it read-only in the app: it cannot be renamed,\n * recoloured, or attached to / detached from an object by hand. Canonical DXOS tags are **not**\n * provider tags — they stay locally toggleable. See {@link getOrigin}.\n */\nexport const isProviderTag = (tag: Type.InstanceType<typeof Tag> | Obj.Snapshot<Type.InstanceType<typeof Tag>>) => {\n const origin = getOrigin(tag);\n return origin !== undefined && origin !== CANONICAL_ORIGIN;\n};\n\nexport const sortTags = ({ label: a }: Type.InstanceType<typeof Tag>, { label: b }: Type.InstanceType<typeof Tag>) =>\n a.localeCompare(b);\n\nexport const createTagList = (tags: Map): Type.InstanceType<typeof Tag>[] =>\n Object.entries(tags)\n .map(([id, tag]) => ({ ...tag, id }))\n .sort(sortTags);\n\nexport const findTagByLabel = (tags: Map | undefined, name: string): Type.InstanceType<typeof Tag> | undefined => {\n const entry = Object.entries(tags ?? {}).find(([_, tag]) => tag.label.toLowerCase() === name.toLowerCase());\n return entry ? { ...entry[1], id: entry[0] } : undefined;\n};\n\n/**\n * Finds a tag by a superseded key and rewrites that key to `key`, so the tag keeps its identity (and\n * every reference to it) across a key-source rename. Returns `undefined` when none match.\n */\nconst adoptLegacyKey = async (\n db: Pick<Database.Database, 'query' | 'add'>,\n key: ForeignKey,\n legacyKeys: readonly ForeignKey[] | undefined,\n): Promise<Type.InstanceType<typeof Tag> | undefined> => {\n if (!legacyKeys?.length) {\n return undefined;\n }\n\n const [existing] = await db.query(Filter.foreignKeys(Tag, [...legacyKeys])).run();\n if (!existing) {\n return undefined;\n }\n\n Obj.update(existing, (existing) => {\n const keys = Obj.getMeta(existing).keys;\n const index = keys.findIndex((candidate) =>\n legacyKeys.some((legacy) => legacy.source === candidate.source && legacy.id === candidate.id),\n );\n if (index >= 0) {\n keys.splice(index, 1, key);\n }\n });\n\n return existing;\n};\n\n/**\n * Finds or creates a {@link Tag} object in the database.\n *\n * - With a foreign `key` (system/provider tags): matched by that key; the label is kept current on\n * re-sync. Use a stable key (e.g. `{ source: 'google.com/gmail/label', id }`) for tags whose\n * identity is external or well-known.\n * - Without a key (user tags): matched by case-insensitive label among tags that carry **no**\n * foreign key, so it never collides with a keyed system/provider tag of the same label.\n *\n * `legacyKeys` lets a caller rename its key source without orphaning existing tags: when the primary\n * key misses, they are tried in order and the first match is rewritten to `key` in place. Without it\n * a rename silently creates a parallel tag on the next sync, while objects keep pointing at the old\n * one. Drop the legacy key once the rename has shipped.\n */\nexport const findOrCreate = async (\n db: Pick<Database.Database, 'query' | 'add'>,\n options: { label: string; hue?: string; key?: ForeignKey; legacyKeys?: readonly ForeignKey[] },\n): Promise<Type.InstanceType<typeof Tag>> => {\n const { label, hue, key, legacyKeys } = options;\n const withHue = hue ? { hue } : {};\n if (key) {\n const [matched] = await db.query(Filter.foreignKeys(Tag, [key])).run();\n const existing = matched ?? (await adoptLegacyKey(db, key, legacyKeys));\n if (existing) {\n // Keep label (and hue, when provided) current on re-sync. `hue` is only touched when supplied,\n // so a label-only re-sync (e.g. Gmail) doesn't wipe a user-set colour.\n if (existing.label !== label || (hue !== undefined && existing.hue !== hue)) {\n Obj.update(existing, (existing) => {\n existing.label = label;\n if (hue !== undefined) {\n existing.hue = hue;\n }\n });\n }\n return existing;\n }\n\n return db.add(Obj.make(Tag, { [Obj.Meta]: { keys: [key] }, label, ...withHue }));\n }\n\n const lowered = label.toLowerCase();\n const candidates = await db.query(Filter.type(Tag)).run();\n const existing = candidates.find(\n (tag) => tag.label.toLowerCase() === lowered && (Obj.getMeta(tag).keys ?? []).length === 0,\n );\n return existing ?? db.add(make({ label, ...withHue }));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAgBA,IAAa,MAAb,cAAyB,WAAqB,UAAmB,CAAC,CAChE,OAAO,OAAO;CACZ,OAAO,OAAO;CACd,KAAK,OAAO,SAAS,OAAO,MAAM;AACpC,CAAC,CAAC,CAAC,KAAA,gBAA8B,IAAI,CAAC,OAAO,CAAC,GAAA,iBAA6B,IAAI,IAAI,CAAC,CACtF,CAAC,CAAC,CAAC;AAEH,IAAa,QAAQ,UAAqC,OAAS,KAAK,KAAK;;;;;;AAS7E,IAAa,mBAAmB;;;;;;;;;;;;;;;AAgBhC,IAAa,aAAa,QACxB,QAAY,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;;AAG5B,IAAa,aAAa,QACxB,UAAU,GAAG,MAAM,KAAA;;;;;;AAOrB,IAAa,iBAAiB,QAAqF;CACjH,MAAM,SAAS,UAAU,GAAG;CAC5B,OAAO,WAAW,KAAA,KAAa,WAAA;AACjC;AAEA,IAAa,YAAY,EAAE,OAAO,KAAoC,EAAE,OAAO,QAC7E,EAAE,cAAc,CAAC;AAEnB,IAAa,iBAAiB,SAC5B,OAAO,QAAQ,IAAI,CAAA,CAChB,KAAK,CAAC,IAAI,UAAU;CAAE,GAAG;CAAK;AAAG,EAAE,CAAA,CACnC,KAAK,QAAQ;AAElB,IAAa,kBAAkB,MAAuB,SAA4D;CAChH,MAAM,QAAQ,OAAO,QAAQ,QAAQ,CAAC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AAG;EAAQ,CAAC,CAAC;CACjF;CAEA,MAAM,UAAU,MAAM,YAAY;CAKlC,QAHiB,MADQ,GAAG,MAAM,KAAY,GAAG,CAAC,CAAC,CAAC,IAAI,EAAA,CAC5B,MACzB,QAAQ,IAAI,MAAM,YAAY,MAAM,YAAY,QAAY,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAA,CAAG,WAAW,CAEpF,KAAY,GAAG,IAAI,KAAK;EAAE;EAAO,GAAG;CAAQ,CAAC,CAAC;AACvD"}
@@ -11,6 +11,35 @@ export declare class Tag extends Tag_base {
11
11
  }
12
12
  export declare const make: (props: Obj.MakeProps<typeof Tag>) => Obj.OfShape<Tag & import("./Entity").OfKind<internal.EntityKind.Object>>;
13
13
  export type Map = Record<string, Type.InstanceType<typeof Tag>>;
14
+ /**
15
+ * Origin domain for DXOS's own canonical tags — provider-agnostic identities (starred, sent, …) that
16
+ * each provider maps its own vocabulary onto, so a Gmail star, a JMAP `$flagged` keyword and a
17
+ * locally-toggled star all resolve to the same {@link Tag}.
18
+ */
19
+ export declare const CANONICAL_ORIGIN = "org.dxos.tag";
20
+ /**
21
+ * The tag's origin domain, or `undefined` when the user created it. Says who owns the tag and
22
+ * therefore who may change it — see `Tag.md` §"Tag origin":
23
+ *
24
+ * - `undefined` — a user tag: rename, recolour, apply and remove are all the user's to do.
25
+ * - {@link CANONICAL_ORIGIN} — a canonical DXOS tag: applied and removed locally, but its label and
26
+ * hue are fixed (a provider may be mapping its own vocabulary onto it).
27
+ * - anything else — a foreign provider domain (e.g. `com.google.gmail`): read-only, since sync owns
28
+ * both the tag and which objects carry it.
29
+ *
30
+ * Read from the tag's first foreign key, which is where {@link findOrCreate} records it; a tag never
31
+ * carries more than one origin. Requires a live entity or snapshot — a spread copy (e.g. from
32
+ * {@link createTagList}) has no metadata and throws rather than reporting a false `undefined`.
33
+ */
34
+ export declare const getOrigin: (tag: Type.InstanceType<typeof Tag> | Obj.Snapshot<Type.InstanceType<typeof Tag>>) => string;
35
+ /** Whether the user created this tag (and so may edit and apply it freely). See {@link getOrigin}. */
36
+ export declare const isUserTag: (tag: Type.InstanceType<typeof Tag> | Obj.Snapshot<Type.InstanceType<typeof Tag>>) => boolean;
37
+ /**
38
+ * Whether a foreign provider owns this tag, making it read-only in the app: it cannot be renamed,
39
+ * recoloured, or attached to / detached from an object by hand. Canonical DXOS tags are **not**
40
+ * provider tags — they stay locally toggleable. See {@link getOrigin}.
41
+ */
42
+ export declare const isProviderTag: (tag: Type.InstanceType<typeof Tag> | Obj.Snapshot<Type.InstanceType<typeof Tag>>) => boolean;
14
43
  export declare const sortTags: ({ label: a }: Type.InstanceType<typeof Tag>, { label: b }: Type.InstanceType<typeof Tag>) => number;
15
44
  export declare const createTagList: (tags: Map) => Type.InstanceType<typeof Tag>[];
16
45
  export declare const findTagByLabel: (tags: Map | undefined, name: string) => Type.InstanceType<typeof Tag> | undefined;
@@ -22,11 +51,17 @@ export declare const findTagByLabel: (tags: Map | undefined, name: string) => Ty
22
51
  * identity is external or well-known.
23
52
  * - Without a key (user tags): matched by case-insensitive label among tags that carry **no**
24
53
  * foreign key, so it never collides with a keyed system/provider tag of the same label.
54
+ *
55
+ * `legacyKeys` lets a caller rename its key source without orphaning existing tags: when the primary
56
+ * key misses, they are tried in order and the first match is rewritten to `key` in place. Without it
57
+ * a rename silently creates a parallel tag on the next sync, while objects keep pointing at the old
58
+ * one. Drop the legacy key once the rename has shipped.
25
59
  */
26
60
  export declare const findOrCreate: (db: Pick<Database.Database, 'query' | 'add'>, options: {
27
61
  label: string;
28
62
  hue?: string;
29
63
  key?: ForeignKey;
64
+ legacyKeys?: readonly ForeignKey[];
30
65
  }) => Promise<Type.InstanceType<typeof Tag>>;
31
66
  export {};
32
67
  //# sourceMappingURL=Tag.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tag.d.ts","sourceRoot":"","sources":["../../../src/Tag.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,q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