@google-cloud/kcmd 0.0.0-stage → 0.2.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.
Files changed (150) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +264 -2
  3. package/build/ts/kcmd/cli.js +20252 -0
  4. package/build/ts/kcmd/gcp/alloydb.d.ts +12 -0
  5. package/build/ts/kcmd/gcp/alloydb.js +70 -0
  6. package/build/ts/kcmd/gcp/api.d.ts +29 -0
  7. package/build/ts/kcmd/gcp/api.js +162 -0
  8. package/build/ts/kcmd/gcp/biglake.d.ts +18 -0
  9. package/build/ts/kcmd/gcp/biglake.js +59 -0
  10. package/build/ts/kcmd/gcp/bigquery.d.ts +57 -0
  11. package/build/ts/kcmd/gcp/bigquery.js +134 -0
  12. package/build/ts/kcmd/gcp/context.d.ts +10 -0
  13. package/build/ts/kcmd/gcp/context.js +74 -0
  14. package/build/ts/kcmd/gcp/crm.d.ts +13 -0
  15. package/build/ts/kcmd/gcp/crm.js +91 -0
  16. package/build/ts/kcmd/gcp/dataplex.d.ts +147 -0
  17. package/build/ts/kcmd/gcp/dataplex.js +406 -0
  18. package/build/ts/kcmd/gcp/index.d.ts +3 -0
  19. package/build/ts/kcmd/gcp/index.js +21 -0
  20. package/build/ts/kcmd/gcp/spanner.d.ts +73 -0
  21. package/build/ts/kcmd/gcp/spanner.js +126 -0
  22. package/build/ts/kcmd/index.d.ts +7 -0
  23. package/build/ts/kcmd/index.js +46 -0
  24. package/build/ts/kcmd/layout.d.ts +16 -0
  25. package/build/ts/kcmd/layout.js +31 -0
  26. package/build/ts/kcmd/layouts/documents.d.ts +24 -0
  27. package/build/ts/kcmd/layouts/documents.js +264 -0
  28. package/build/ts/kcmd/layouts/okf.d.ts +31 -0
  29. package/build/ts/kcmd/layouts/okf.js +386 -0
  30. package/build/ts/kcmd/layouts/semantic-model.d.ts +74 -0
  31. package/build/ts/kcmd/layouts/semantic-model.js +621 -0
  32. package/build/ts/kcmd/layouts/standard.d.ts +13 -0
  33. package/build/ts/kcmd/layouts/standard.js +108 -0
  34. package/build/ts/kcmd/manifest.d.ts +34 -0
  35. package/build/ts/kcmd/manifest.js +262 -0
  36. package/build/ts/kcmd/metadata.d.ts +25 -0
  37. package/build/ts/kcmd/metadata.js +8 -0
  38. package/build/ts/kcmd/okf/catalog_residue.d.ts +14 -0
  39. package/build/ts/kcmd/okf/catalog_residue.js +124 -0
  40. package/build/ts/kcmd/okf/concept.d.ts +14 -0
  41. package/build/ts/kcmd/okf/concept.js +110 -0
  42. package/build/ts/kcmd/okf/concept_to_entry.d.ts +10 -0
  43. package/build/ts/kcmd/okf/concept_to_entry.js +281 -0
  44. package/build/ts/kcmd/okf/init_okf_workspace.d.ts +15 -0
  45. package/build/ts/kcmd/okf/init_okf_workspace.js +113 -0
  46. package/build/ts/kcmd/okf/links.d.ts +23 -0
  47. package/build/ts/kcmd/okf/links.js +468 -0
  48. package/build/ts/kcmd/okf/okf_metadata.d.ts +12 -0
  49. package/build/ts/kcmd/okf/okf_metadata.js +99 -0
  50. package/build/ts/kcmd/semantic/bigquery.d.ts +22 -0
  51. package/build/ts/kcmd/semantic/bigquery.js +469 -0
  52. package/build/ts/kcmd/semantic/binding.d.ts +3 -0
  53. package/build/ts/kcmd/semantic/binding.js +92 -0
  54. package/build/ts/kcmd/semantic/catalog_entry.d.ts +24 -0
  55. package/build/ts/kcmd/semantic/catalog_entry.js +35 -0
  56. package/build/ts/kcmd/semantic/converters/owl/convert.d.ts +26 -0
  57. package/build/ts/kcmd/semantic/converters/owl/convert.js +41 -0
  58. package/build/ts/kcmd/semantic/converters/owl/model.d.ts +98 -0
  59. package/build/ts/kcmd/semantic/converters/owl/model.js +30 -0
  60. package/build/ts/kcmd/semantic/converters/owl/parse.d.ts +11 -0
  61. package/build/ts/kcmd/semantic/converters/owl/parse.js +634 -0
  62. package/build/ts/kcmd/semantic/converters/owl/to_ir.d.ts +19 -0
  63. package/build/ts/kcmd/semantic/converters/owl/to_ir.js +390 -0
  64. package/build/ts/kcmd/semantic/deploy_bigquery.d.ts +20 -0
  65. package/build/ts/kcmd/semantic/deploy_bigquery.js +226 -0
  66. package/build/ts/kcmd/semantic/deploy_knowledge_catalog.d.ts +104 -0
  67. package/build/ts/kcmd/semantic/deploy_knowledge_catalog.js +1367 -0
  68. package/build/ts/kcmd/semantic/deploy_spanner.d.ts +15 -0
  69. package/build/ts/kcmd/semantic/deploy_spanner.js +150 -0
  70. package/build/ts/kcmd/semantic/deployment_target.d.ts +93 -0
  71. package/build/ts/kcmd/semantic/deployment_target.js +379 -0
  72. package/build/ts/kcmd/semantic/graph_ddl.d.ts +44 -0
  73. package/build/ts/kcmd/semantic/graph_ddl.js +656 -0
  74. package/build/ts/kcmd/semantic/import_model.d.ts +72 -0
  75. package/build/ts/kcmd/semantic/import_model.js +1698 -0
  76. package/build/ts/kcmd/semantic/ir.d.ts +589 -0
  77. package/build/ts/kcmd/semantic/ir.js +247 -0
  78. package/build/ts/kcmd/semantic/kc_actions.d.ts +45 -0
  79. package/build/ts/kcmd/semantic/kc_actions.js +531 -0
  80. package/build/ts/kcmd/semantic/kc_constraints.d.ts +44 -0
  81. package/build/ts/kcmd/semantic/kc_constraints.js +279 -0
  82. package/build/ts/kcmd/semantic/kc_converter.d.ts +37 -0
  83. package/build/ts/kcmd/semantic/kc_converter.js +839 -0
  84. package/build/ts/kcmd/semantic/kc_custom_types.d.ts +63 -0
  85. package/build/ts/kcmd/semantic/kc_custom_types.js +751 -0
  86. package/build/ts/kcmd/semantic/kc_entries.d.ts +155 -0
  87. package/build/ts/kcmd/semantic/kc_entries.js +284 -0
  88. package/build/ts/kcmd/semantic/kc_ids.d.ts +102 -0
  89. package/build/ts/kcmd/semantic/kc_ids.js +188 -0
  90. package/build/ts/kcmd/semantic/knowledge_catalog.d.ts +29 -0
  91. package/build/ts/kcmd/semantic/knowledge_catalog.js +960 -0
  92. package/build/ts/kcmd/semantic/loader.d.ts +258 -0
  93. package/build/ts/kcmd/semantic/loader.js +3576 -0
  94. package/build/ts/kcmd/semantic/names.d.ts +10 -0
  95. package/build/ts/kcmd/semantic/names.js +85 -0
  96. package/build/ts/kcmd/semantic/osi_converter.d.ts +60 -0
  97. package/build/ts/kcmd/semantic/osi_converter.js +910 -0
  98. package/build/ts/kcmd/semantic/parameters.d.ts +19 -0
  99. package/build/ts/kcmd/semantic/parameters.js +171 -0
  100. package/build/ts/kcmd/semantic/pull_kc.d.ts +10 -0
  101. package/build/ts/kcmd/semantic/pull_kc.js +272 -0
  102. package/build/ts/kcmd/semantic/resolve_inheritance.d.ts +59 -0
  103. package/build/ts/kcmd/semantic/resolve_inheritance.js +346 -0
  104. package/build/ts/kcmd/semantic/resolve_profiles.d.ts +291 -0
  105. package/build/ts/kcmd/semantic/resolve_profiles.js +2003 -0
  106. package/build/ts/kcmd/semantic/runtime/agent_tools.d.ts +93 -0
  107. package/build/ts/kcmd/semantic/runtime/agent_tools.js +243 -0
  108. package/build/ts/kcmd/semantic/runtime/dialect.d.ts +13 -0
  109. package/build/ts/kcmd/semantic/runtime/dialect.js +39 -0
  110. package/build/ts/kcmd/semantic/runtime/runtime.d.ts +88 -0
  111. package/build/ts/kcmd/semantic/runtime/runtime.js +301 -0
  112. package/build/ts/kcmd/semantic/runtime/store.d.ts +112 -0
  113. package/build/ts/kcmd/semantic/runtime/store.js +344 -0
  114. package/build/ts/kcmd/semantic/skills.d.ts +110 -0
  115. package/build/ts/kcmd/semantic/skills.js +697 -0
  116. package/build/ts/kcmd/semantic/source_dialect.d.ts +17 -0
  117. package/build/ts/kcmd/semantic/source_dialect.js +311 -0
  118. package/build/ts/kcmd/semantic/source_entries.d.ts +12 -0
  119. package/build/ts/kcmd/semantic/source_entries.js +341 -0
  120. package/build/ts/kcmd/semantic/spanner.d.ts +18 -0
  121. package/build/ts/kcmd/semantic/spanner.js +60 -0
  122. package/build/ts/kcmd/semantic/sql_expr_utils.d.ts +23 -0
  123. package/build/ts/kcmd/semantic/sql_expr_utils.js +394 -0
  124. package/build/ts/kcmd/semantic/sql_identifiers.d.ts +6 -0
  125. package/build/ts/kcmd/semantic/sql_identifiers.js +267 -0
  126. package/build/ts/kcmd/semantic/sql_parser.d.ts +47 -0
  127. package/build/ts/kcmd/semantic/sql_parser.js +400 -0
  128. package/build/ts/kcmd/semantic/transpile.d.ts +76 -0
  129. package/build/ts/kcmd/semantic/transpile.js +581 -0
  130. package/build/ts/kcmd/semantic/validate.d.ts +70 -0
  131. package/build/ts/kcmd/semantic/validate.js +2266 -0
  132. package/build/ts/kcmd/semantic/yaml_options.d.ts +6 -0
  133. package/build/ts/kcmd/semantic/yaml_options.js +58 -0
  134. package/build/ts/kcmd/semantic/yaml_update.d.ts +26 -0
  135. package/build/ts/kcmd/semantic/yaml_update.js +782 -0
  136. package/build/ts/kcmd/snapshot.d.ts +37 -0
  137. package/build/ts/kcmd/snapshot.js +386 -0
  138. package/build/ts/kcmd/source.d.ts +31 -0
  139. package/build/ts/kcmd/source.js +119 -0
  140. package/build/ts/kcmd/sources/bq-dataset.d.ts +17 -0
  141. package/build/ts/kcmd/sources/bq-dataset.js +131 -0
  142. package/build/ts/kcmd/sources/entrygroup.d.ts +21 -0
  143. package/build/ts/kcmd/sources/entrygroup.js +83 -0
  144. package/build/ts/kcmd/sources/kb.d.ts +21 -0
  145. package/build/ts/kcmd/sources/kb.js +82 -0
  146. package/build/ts/kcmd/sources/semantic-model.d.ts +18 -0
  147. package/build/ts/kcmd/sources/semantic-model.js +48 -0
  148. package/build/ts/kcmd/sync.d.ts +35 -0
  149. package/build/ts/kcmd/sync.js +734 -0
  150. package/package.json +62 -4
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ // Knowledge Catalog resource naming and ID helpers.
3
+ //
4
+ // Provides a shared set of rules for constructing and parsing Knowledge Catalog
5
+ // resource names across the emitter, model validation, the catalog reader, and
6
+ // the deployment pipeline. This module imports only the IR to avoid circular
7
+ // dependencies.
8
+ //
9
+ // Terminology used in this module:
10
+ // - A "full resource name" includes the GCP container path, e.g.
11
+ // `projects/<p>/locations/<l>/entryGroups/<eg>/entries/<entryId>`.
12
+ // - A "bare entry ID" (or "entry-link ID") is the trailing `<entryId>`
13
+ // (or `<linkId>`) segment without the container prefix, e.g.
14
+ // `retail_sales.entities.store_orders` (V1) or
15
+ // `retail_sales/entities/store_orders` (V2).
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Namer = exports.DEFAULT_TYPE_LOCATION = exports.DEFAULT_TYPE_PROJECT = void 0;
18
+ exports.relationshipLinkId = relationshipLinkId;
19
+ exports.semanticLinkId = semanticLinkId;
20
+ exports.ownedEntryIdPrefixes = ownedEntryIdPrefixes;
21
+ exports.entryIdOf = entryIdOf;
22
+ exports.slug = slug;
23
+ exports.linkSlug = linkSlug;
24
+ const node_crypto_1 = require("node:crypto");
25
+ // Where the `semantic-*` and `schema` system types live: built-in types in
26
+ // project `dataplex-types`, location `global`. Callers may override to
27
+ // reference them from a staging project.
28
+ exports.DEFAULT_TYPE_PROJECT = 'dataplex-types';
29
+ exports.DEFAULT_TYPE_LOCATION = 'global';
30
+ // Matches the container path and trailing bare ID of any Knowledge Catalog
31
+ // resource name:
32
+ // - Entry-group paths (`ENTRY_GROUP_PATH_RE`):
33
+ // `projects/<p>/locations/<l>/entryGroups/<eg>/(entries|entryLinks)/<id>`
34
+ // - Type paths (`TYPE_PATH_RE`):
35
+ // `projects/<p>/locations/<l>/(entryTypes|aspectTypes|entryLinkTypes)/<id>`
36
+ const ENTRY_GROUP_PATH_RE = /entryGroups\/[^/]+\/(?:entries|entryLinks)/;
37
+ const TYPE_PATH_RE = /entryTypes|aspectTypes|entryLinkTypes/;
38
+ const RESOURCE_ID_RE = new RegExp(`^projects/[^/]+/locations/[^/]+/` +
39
+ `(?:${ENTRY_GROUP_PATH_RE.source}|${TYPE_PATH_RE.source})/(.+)$`);
40
+ /**
41
+ * Builds the fully-qualified resource names and bare entry/link IDs for a
42
+ * destination. Kept in one place so entry/type name construction is consistent
43
+ * and the emitter body reads as pure mapping.
44
+ */
45
+ class Namer {
46
+ typeProject;
47
+ typeLocation;
48
+ container;
49
+ v2Aspects;
50
+ constructor(opts) {
51
+ this.typeProject = opts.systemTypeProject ?? exports.DEFAULT_TYPE_PROJECT;
52
+ this.typeLocation = opts.systemTypeLocation ?? exports.DEFAULT_TYPE_LOCATION;
53
+ this.container = `projects/${opts.project}/locations/${opts.location}/entryGroups/${opts.entryGroup}`;
54
+ this.v2Aspects = opts.v2Aspects ?? false;
55
+ }
56
+ /** Full resource name of a system type. `kind` selects the collection. */
57
+ typeName(kind, name) {
58
+ return `projects/${this.typeProject}/locations/${this.typeLocation}/${kind}Types/${name}`;
59
+ }
60
+ /**
61
+ * Aspect-map key: the `project.location.type` reference form the client keys
62
+ * an entry's aspects by (see dataplex._nameToTypeRef / _fixEntry).
63
+ */
64
+ aspectRef(name) {
65
+ return `${this.typeProject}.${this.typeLocation}.${name}`;
66
+ }
67
+ /** Full resource name of an entry in the destination entry group. */
68
+ entry(entryId) {
69
+ return `${this.container}/entries/${entryId}`;
70
+ }
71
+ /** Full resource name of an entry link in the destination entry group. */
72
+ entryLink(linkId) {
73
+ return `${this.container}/entryLinks/${linkId}`;
74
+ }
75
+ /**
76
+ * Bare entry ID for a semantic model, used as the `semantic-model` anchor
77
+ * entry's ID and as the prefix for action and constraint entry IDs.
78
+ *
79
+ * V1 sanitizes `model.name` with `slug()` because `model.name` may contain
80
+ * characters (e.g. spaces) that Knowledge Catalog disallows in entry IDs.
81
+ * V2 returns `model.name` verbatim because V2 model names are restricted to
82
+ * letters, digits, underscores and hyphens, all of which `slug()` keeps. This
83
+ * means `slug(model.name)` and `model.name` are equal for valid V2 models.
84
+ */
85
+ modelId(model) {
86
+ return this.v2Aspects ? model.name : slug(model.name);
87
+ }
88
+ /** Bare entry ID for an entity within a semantic model. */
89
+ entityId(model, entity) {
90
+ return this.v2Aspects ?
91
+ `${model.name}/entities/${entity.name}` :
92
+ `${slug(model.name)}.entities.${slug(entity.name)}`;
93
+ }
94
+ /** Bare entry ID for a metric within a semantic model. */
95
+ metricId(model, metric) {
96
+ return this.v2Aspects ?
97
+ `${model.name}/metrics/${metric.name}` :
98
+ `${slug(model.name)}.metrics.${slug(metric.name)}`;
99
+ }
100
+ /** Bare V2 entry ID for a relationship within a semantic model. */
101
+ relationshipId(model, rel) {
102
+ return `${model.name}/relationships/${rel.name}`;
103
+ }
104
+ /**
105
+ * Entry link IDs are more restricted than entry IDs: lowercase letters,
106
+ * numbers and hyphens only, starting with a letter (see `linkSlug`). Does not
107
+ * branch on `v2Aspects`.
108
+ */
109
+ linkId(model, rel) {
110
+ return relationshipLinkId(model.name, rel.name);
111
+ }
112
+ }
113
+ exports.Namer = Namer;
114
+ /** Entry-link ID for a relationship on a model. */
115
+ function relationshipLinkId(modelName, relName) {
116
+ return linkSlug(`${modelName}-${relName}`);
117
+ }
118
+ /**
119
+ * ID of a link push writes: `semantic-<kind>-` and the first 32 hex characters
120
+ * of the SHA-256 of `parts` joined by '/'. It must stay the same across
121
+ * releases, so that push finds the links it wrote.
122
+ */
123
+ function semanticLinkId(kind, ...parts) {
124
+ const digest = (0, node_crypto_1.createHash)('sha256').update(parts.join('/'), 'utf8').digest('hex');
125
+ return `semantic-${kind}-${digest.slice(0, 32)}`;
126
+ }
127
+ /**
128
+ * Entry-ID prefixes owned by `modelName` across both the first-generation
129
+ * dotted layout and the second-generation slash layout.
130
+ *
131
+ * The dotted prefixes use `slug(modelName)` to match V1 entries, while the
132
+ * slash prefixes use `modelName` verbatim to match V2 entity, metric and
133
+ * relationship entries. Because V2 model names are restricted to letters,
134
+ * digits, underscores and hyphens, all of which `slug()` keeps,
135
+ * `slug(modelName)` and `modelName` are equal for valid V2 models.
136
+ *
137
+ * No push writes under `.files.` any more: an older kcmd stored a copy of
138
+ * each model and profile file there. The prefix stays so the next push
139
+ * deletes those copies.
140
+ */
141
+ function ownedEntryIdPrefixes(modelName) {
142
+ const s = slug(modelName);
143
+ return [
144
+ `${s}.entities.`,
145
+ `${s}.metrics.`,
146
+ `${s}.actions.`,
147
+ `${s}.constraints.`,
148
+ `${s}.files.`,
149
+ `${modelName}/entities/`,
150
+ `${modelName}/metrics/`,
151
+ `${modelName}/relationships/`,
152
+ ];
153
+ }
154
+ /**
155
+ * Extracts the bare resource ID from a full Knowledge Catalog resource name
156
+ * (entry, entry link, or type), or returns `resourceName` unchanged if it does
157
+ * not match a known resource container.
158
+ *
159
+ * Matches known container collections via `RESOURCE_ID_RE` and leaves
160
+ * non-matching strings untouched, rather than falling back to
161
+ * `.split('/').pop()` (which would corrupt an already-bare V2 slash entry ID
162
+ * like `'retail_sales/entities/store_orders'` into `'store_orders'`).
163
+ */
164
+ function entryIdOf(resourceName) {
165
+ const m = resourceName.match(RESOURCE_ID_RE);
166
+ return m ? m[1] : resourceName;
167
+ }
168
+ /**
169
+ * Entry IDs allow letters, numbers, underscores, hyphens, and periods; maps
170
+ * anything else to an underscore.
171
+ */
172
+ function slug(s) {
173
+ return s.replace(/[^A-Za-z0-9_.-]/g, '_');
174
+ }
175
+ /**
176
+ * Entry link IDs allow only lowercase letters, numbers and hyphens, must start
177
+ * with a letter, must end with a letter or number, and are capped at 63 chars.
178
+ */
179
+ function linkSlug(s) {
180
+ const out = s.toLowerCase()
181
+ .replace(/[^a-z0-9-]+/g, '-')
182
+ .replace(/-+/g, '-')
183
+ .replace(/^[^a-z]+/, '')
184
+ .replace(/^-+|-+$/g, '')
185
+ .slice(0, 63)
186
+ .replace(/-+$/, '');
187
+ return out || 'link';
188
+ }
@@ -0,0 +1,29 @@
1
+ import type { Entry, EntryLink } from '../gcp/dataplex';
2
+ import type { OverviewSidecar } from '../layouts/semantic-model';
3
+ import { SemanticModel } from './ir';
4
+ export interface KcGenerateOptions {
5
+ project: string;
6
+ location: string;
7
+ entryGroup: string;
8
+ systemTypeProject?: string;
9
+ systemTypeLocation?: string;
10
+ emitExpressions?: boolean;
11
+ v2Aspects?: boolean;
12
+ overviews?: ReadonlyMap<string, OverviewSidecar>;
13
+ }
14
+ export interface KcResources {
15
+ entries: Entry[];
16
+ entryLinks: EntryLink[];
17
+ warnings: string[];
18
+ ownedPrefixes: string[];
19
+ }
20
+ /**
21
+ * Generates the Knowledge Catalog resources for a semantic model.
22
+ *
23
+ * Returns the entries (model anchor first, then entities, metrics and, with
24
+ * v2Aspects, relationships), the entry links of the relationships and, with
25
+ * v2Aspects, of each entity's parents, and any warnings collected while
26
+ * mapping the IR (missing keys, un-typed metrics, skipped M:N relationships).
27
+ * The resources reference the built-in system types; they do not create them.
28
+ */
29
+ export declare function generateCatalogResources(model: SemanticModel, opts: KcGenerateOptions): KcResources;