@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,10 @@
1
+ export type NameKind = 'model' | 'profile' | 'deployment' | 'entity' | 'metric' | 'relationship' | 'field';
2
+ export declare function nameProblem(kind: NameKind, name: string): string | undefined;
3
+ export declare const MAX_ENTRY_DESCRIPTION = 2000;
4
+ export declare const MAX_BIGQUERY_DESCRIPTION = 1024;
5
+ export declare const MAX_BIGQUERY_SYNONYM_COUNT = 8;
6
+ export declare const MAX_BIGQUERY_SYNONYM_LENGTH = 300;
7
+ export declare function qualifierCaseError(where: string, col: {
8
+ qualifier?: string;
9
+ name: string;
10
+ }, entityNames: string[]): string | undefined;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ // The names a semantic model may give its parts. A name does not stay in the
3
+ // model file: it is joined into a Knowledge Catalog entry id, written into
4
+ // SQL and graph queries, used as a profile's filename and passed on a
5
+ // comma-separated flag. One pattern per kind keeps a name safe in all of them,
6
+ // so there is no list of forbidden characters to keep up to date.
7
+ //
8
+ // - A model, profile or deployment name may contain a hyphen, as in
9
+ // `sales-analytics`: none of them appears in SQL or a graph query.
10
+ // - An entity, metric or relationship name appears in expressions, the graph
11
+ // DDL and graph queries, so it may not.
12
+ // - A field name is a BigQuery column name, so it may begin with an underscore
13
+ // and is capped shorter.
14
+ // The 500-character cap is a Knowledge Catalog limit.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.MAX_BIGQUERY_SYNONYM_LENGTH = exports.MAX_BIGQUERY_SYNONYM_COUNT = exports.MAX_BIGQUERY_DESCRIPTION = exports.MAX_ENTRY_DESCRIPTION = void 0;
17
+ exports.nameProblem = nameProblem;
18
+ exports.qualifierCaseError = qualifierCaseError;
19
+ const WITH_HYPHEN = {
20
+ pattern: /^[A-Za-z][A-Za-z0-9_-]*$/,
21
+ shown: '^[A-Za-z][A-Za-z0-9_-]*$',
22
+ says: 'a letter, then letters, digits, underscores or hyphens',
23
+ max: 500,
24
+ };
25
+ const IN_SQL = {
26
+ pattern: /^[A-Za-z][A-Za-z0-9_]*$/,
27
+ shown: '^[A-Za-z][A-Za-z0-9_]*$',
28
+ says: 'a letter, then letters, digits or underscores',
29
+ max: 500,
30
+ };
31
+ const FIELD = {
32
+ pattern: /^[A-Za-z_][A-Za-z0-9_]*$/,
33
+ shown: '^[A-Za-z_][A-Za-z0-9_]{0,299}$',
34
+ says: 'a letter or underscore, then letters, digits or underscores',
35
+ max: 300,
36
+ };
37
+ const RULES = {
38
+ model: WITH_HYPHEN,
39
+ profile: WITH_HYPHEN,
40
+ deployment: WITH_HYPHEN,
41
+ entity: IN_SQL,
42
+ metric: IN_SQL,
43
+ relationship: IN_SQL,
44
+ field: FIELD,
45
+ };
46
+ const LABEL = {
47
+ model: 'Model',
48
+ profile: 'Profile',
49
+ deployment: 'Deployment',
50
+ entity: 'Entity',
51
+ metric: 'Metric',
52
+ relationship: 'Relationship',
53
+ field: 'Field',
54
+ };
55
+ // Why `name` is not a valid name for a `kind`, or undefined when it is. A name
56
+ // over the length limit is shown cut short, so the message stays readable.
57
+ function nameProblem(kind, name) {
58
+ const rule = RULES[kind];
59
+ if (name.length > rule.max) {
60
+ return `${LABEL[kind]} name '${Array.from(name).slice(0, 40).join('')}...' is ${name.length} characters long; names may be at most ${rule.max} characters.`;
61
+ }
62
+ if (!rule.pattern.test(name)) {
63
+ return `${LABEL[kind]} name '${name}' is not valid; names must match ${rule.shown}: ${rule.says}.`;
64
+ }
65
+ return undefined;
66
+ }
67
+ // The most characters a description stored as a Knowledge Catalog entry's
68
+ // description may have: the model's, an entity's, a metric's and a
69
+ // relationship's.
70
+ exports.MAX_ENTRY_DESCRIPTION = 2000;
71
+ // BigQuery's limits on the OPTIONS of a graph label or property.
72
+ exports.MAX_BIGQUERY_DESCRIPTION = 1024;
73
+ exports.MAX_BIGQUERY_SYNONYM_COUNT = 8;
74
+ exports.MAX_BIGQUERY_SYNONYM_LENGTH = 300;
75
+ // The error for a reference whose qualifier matches one of `entityNames` only
76
+ // when case is ignored, or undefined. `where` names the field or metric.
77
+ function qualifierCaseError(where, col, entityNames) {
78
+ const q = col.qualifier;
79
+ if (q === undefined || entityNames.includes(q))
80
+ return undefined;
81
+ const entity = entityNames.find(n => n.toLowerCase() === q.toLowerCase());
82
+ return entity &&
83
+ `${where}: '${q}.${col.name}' uses qualifier '${q}', which differs in ` +
84
+ `case from entity '${entity}'; entity names are case-sensitive.`;
85
+ }
@@ -0,0 +1,60 @@
1
+ import { SemanticModel } from './ir';
2
+ export interface SerializedFile {
3
+ fileName: string;
4
+ content: string;
5
+ }
6
+ export interface SerializeFilesResult {
7
+ files: SerializedFile[];
8
+ warnings: string[];
9
+ }
10
+ export interface SerializeResult {
11
+ yaml: string;
12
+ warnings: string[];
13
+ }
14
+ export interface SerializeOptions {
15
+ logical?: boolean;
16
+ compactFlow?: boolean;
17
+ /**
18
+ * The column at which a long string is folded onto the next line; 0 keeps
19
+ * every value on one line. Defaults to 80.
20
+ */
21
+ lineWidth?: number;
22
+ }
23
+ /**
24
+ * Serializes a semantic model and its sidecar profile files. The returned
25
+ * `files` list always starts with `<model.name>.yaml`. Under `GOOGLE_VERSION`,
26
+ * each entry in `model.profiles` follows as
27
+ * `<model.name>.profile.<profile.name>.yaml`, except that a reserved
28
+ * (`default`), invalid, or case-insensitively repeated name is skipped with a
29
+ * warning. Under `OSSIE_VERSION`, valid profiles are written into the model's
30
+ * `GOOGLE` `custom_extensions` block and no profile files are emitted.
31
+ */
32
+ export declare function serializeModelFiles(model: SemanticModel, opts?: SerializeOptions): SerializeFilesResult;
33
+ /**
34
+ * Serializes a single semantic model to a YAML document string in the open
35
+ * AI-first semantics format. The document contains exactly this one model;
36
+ * `pull` writes one file per model
37
+ * (catalog/EntryGroups/<entryGroup>/<model>.yaml). It is the first file
38
+ * `serializeModelFiles` returns, with the warnings for every file it builds.
39
+ *
40
+ * Warnings flag IR content that has no loadable representation (an association
41
+ * relationship's junction detail, an imported expression in an unknown dialect,
42
+ * dropped `GOOGLE` blocks under GOOGLE_VERSION, Google-only constructs and
43
+ * missing join columns under OSSIE_VERSION, or loader-invalid gaps), so the
44
+ * caller can surface the lossy edge.
45
+ *
46
+ * `logical` marks the model as a purely logical one (no physical binding).
47
+ * Under GOOGLE_VERSION it suppresses the missing-source and missing-expression
48
+ * warnings, which flag a lossy pull of a bound model. OSSIE_VERSION requires
49
+ * both, so they are still given. An OWL import sets it, and so does a
50
+ * second-generation pull, which loses no binding.
51
+ *
52
+ * `compactFlow` renders leaf collections (scalar sequences, all-scalar maps) in
53
+ * flow style so the output matches the compact convention the semantic-model
54
+ * guides author by hand and is byte-for-byte reproducible there. An OWL import
55
+ * sets it; `pull` does not.
56
+ */
57
+ export declare function serializeModel(model: SemanticModel, opts?: SerializeOptions): SerializeResult;
58
+ export declare function modelDocument(model: SemanticModel, warnings?: string[], logical?: boolean): Record<string, any>;
59
+ export declare function compact<T extends Record<string, any>>(obj: T): T;
60
+ export declare function nonEmpty<T>(items: T[] | undefined): T[] | undefined;