dataiku-sdk 0.10.1 → 0.12.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 (151) hide show
  1. package/LICENSE +21 -0
  2. package/dist/packages/types/src/index.d.ts +19 -2
  3. package/dist/packages/types/src/index.js +13 -1
  4. package/dist/src/cli/coerce.d.ts +36 -0
  5. package/dist/src/cli/coerce.js +239 -0
  6. package/dist/src/cli/commands/analysis.d.ts +2 -0
  7. package/dist/src/cli/commands/analysis.js +66 -0
  8. package/dist/src/cli/commands/api-deployer.d.ts +2 -0
  9. package/dist/src/cli/commands/api-deployer.js +170 -0
  10. package/dist/src/cli/commands/api-service.d.ts +2 -0
  11. package/dist/src/cli/commands/api-service.js +121 -0
  12. package/dist/src/cli/commands/app.d.ts +2 -0
  13. package/dist/src/cli/commands/app.js +78 -0
  14. package/dist/src/cli/commands/bundle.d.ts +2 -0
  15. package/dist/src/cli/commands/bundle.js +107 -0
  16. package/dist/src/cli/commands/business-app.d.ts +2 -0
  17. package/dist/src/cli/commands/business-app.js +76 -0
  18. package/dist/src/cli/commands/code-env.d.ts +2 -0
  19. package/dist/src/cli/commands/code-env.js +255 -0
  20. package/dist/src/cli/commands/code.d.ts +2 -0
  21. package/dist/src/cli/commands/code.js +63 -0
  22. package/dist/src/cli/commands/connection.d.ts +2 -0
  23. package/dist/src/cli/commands/connection.js +54 -0
  24. package/dist/src/cli/commands/continuous-activity.d.ts +2 -0
  25. package/dist/src/cli/commands/continuous-activity.js +38 -0
  26. package/dist/src/cli/commands/dashboard.d.ts +2 -0
  27. package/dist/src/cli/commands/dashboard.js +99 -0
  28. package/dist/src/cli/commands/data-quality.d.ts +2 -0
  29. package/dist/src/cli/commands/data-quality.js +235 -0
  30. package/dist/src/cli/commands/dataset.d.ts +2 -0
  31. package/dist/src/cli/commands/dataset.js +288 -0
  32. package/dist/src/cli/commands/discussion.d.ts +2 -0
  33. package/dist/src/cli/commands/discussion.js +47 -0
  34. package/dist/src/cli/commands/doctor.d.ts +2 -0
  35. package/dist/src/cli/commands/doctor.js +9 -0
  36. package/dist/src/cli/commands/flow-zone.d.ts +2 -0
  37. package/dist/src/cli/commands/flow-zone.js +282 -0
  38. package/dist/src/cli/commands/folder.d.ts +2 -0
  39. package/dist/src/cli/commands/folder.js +202 -0
  40. package/dist/src/cli/commands/future.d.ts +2 -0
  41. package/dist/src/cli/commands/future.js +57 -0
  42. package/dist/src/cli/commands/index.d.ts +2 -0
  43. package/dist/src/cli/commands/index.js +78 -0
  44. package/dist/src/cli/commands/insight.d.ts +2 -0
  45. package/dist/src/cli/commands/insight.js +156 -0
  46. package/dist/src/cli/commands/job.d.ts +2 -0
  47. package/dist/src/cli/commands/job.js +406 -0
  48. package/dist/src/cli/commands/meaning.d.ts +2 -0
  49. package/dist/src/cli/commands/meaning.js +115 -0
  50. package/dist/src/cli/commands/metrics.d.ts +2 -0
  51. package/dist/src/cli/commands/metrics.js +39 -0
  52. package/dist/src/cli/commands/ml-task.d.ts +2 -0
  53. package/dist/src/cli/commands/ml-task.js +171 -0
  54. package/dist/src/cli/commands/model-evaluation-store.d.ts +2 -0
  55. package/dist/src/cli/commands/model-evaluation-store.js +83 -0
  56. package/dist/src/cli/commands/notebook.d.ts +2 -0
  57. package/dist/src/cli/commands/notebook.js +242 -0
  58. package/dist/src/cli/commands/project-deployer.d.ts +2 -0
  59. package/dist/src/cli/commands/project-deployer.js +118 -0
  60. package/dist/src/cli/commands/project-library.d.ts +2 -0
  61. package/dist/src/cli/commands/project-library.js +197 -0
  62. package/dist/src/cli/commands/project.d.ts +2 -0
  63. package/dist/src/cli/commands/project.js +133 -0
  64. package/dist/src/cli/commands/recipe.d.ts +2 -0
  65. package/dist/src/cli/commands/recipe.js +659 -0
  66. package/dist/src/cli/commands/saved-model.d.ts +2 -0
  67. package/dist/src/cli/commands/saved-model.js +85 -0
  68. package/dist/src/cli/commands/scenario.d.ts +2 -0
  69. package/dist/src/cli/commands/scenario.js +190 -0
  70. package/dist/src/cli/commands/sql.d.ts +2 -0
  71. package/dist/src/cli/commands/sql.js +109 -0
  72. package/dist/src/cli/commands/statistics.d.ts +2 -0
  73. package/dist/src/cli/commands/statistics.js +165 -0
  74. package/dist/src/cli/commands/streaming-endpoint.d.ts +2 -0
  75. package/dist/src/cli/commands/streaming-endpoint.js +50 -0
  76. package/dist/src/cli/commands/variable.d.ts +2 -0
  77. package/dist/src/cli/commands/variable.js +49 -0
  78. package/dist/src/cli/commands/webapp.d.ts +2 -0
  79. package/dist/src/cli/commands/webapp.js +67 -0
  80. package/dist/src/cli/commands/wiki.d.ts +2 -0
  81. package/dist/src/cli/commands/wiki.js +123 -0
  82. package/dist/src/cli/commands/workspace.d.ts +2 -0
  83. package/dist/src/cli/commands/workspace.js +68 -0
  84. package/dist/src/cli/contract.d.ts +104 -0
  85. package/dist/src/cli/contract.js +2041 -0
  86. package/dist/src/cli/doctor.d.ts +104 -0
  87. package/dist/src/cli/doctor.js +356 -0
  88. package/dist/src/cli/env.d.ts +2 -0
  89. package/dist/src/cli/env.js +37 -0
  90. package/dist/src/cli/flags.d.ts +16 -0
  91. package/dist/src/cli/flags.js +272 -0
  92. package/dist/src/cli/helpers/cleanup.d.ts +3 -0
  93. package/dist/src/cli/helpers/cleanup.js +204 -0
  94. package/dist/src/cli/helpers/dataset.d.ts +2 -0
  95. package/dist/src/cli/helpers/dataset.js +17 -0
  96. package/dist/src/cli/helpers/flow-zone.d.ts +69 -0
  97. package/dist/src/cli/helpers/flow-zone.js +420 -0
  98. package/dist/src/cli/helpers/recipe.d.ts +11 -0
  99. package/dist/src/cli/helpers/recipe.js +83 -0
  100. package/dist/src/cli/output.d.ts +38 -0
  101. package/dist/src/cli/output.js +159 -0
  102. package/dist/src/cli/runtime.d.ts +15 -0
  103. package/dist/src/cli/runtime.js +59 -0
  104. package/dist/src/cli/types.d.ts +25 -0
  105. package/dist/src/cli/types.js +1 -0
  106. package/dist/src/cli/usage.d.ts +16 -0
  107. package/dist/src/cli/usage.js +84 -0
  108. package/dist/src/cli/version.d.ts +14 -0
  109. package/dist/src/cli/version.js +63 -0
  110. package/dist/src/cli.js +671 -8254
  111. package/dist/src/client.d.ts +13 -1
  112. package/dist/src/client.js +34 -13
  113. package/dist/src/errors.d.ts +6 -0
  114. package/dist/src/errors.js +102 -4
  115. package/dist/src/index.d.ts +7 -3
  116. package/dist/src/index.js +6 -2
  117. package/dist/src/resources/analyses.d.ts +34 -0
  118. package/dist/src/resources/analyses.js +31 -0
  119. package/dist/src/resources/api-services.d.ts +2 -0
  120. package/dist/src/resources/api-services.js +10 -0
  121. package/dist/src/resources/applications.d.ts +1 -1
  122. package/dist/src/resources/applications.js +27 -1
  123. package/dist/src/resources/continuous-activities.js +1 -0
  124. package/dist/src/resources/data-quality.js +5 -3
  125. package/dist/src/resources/datasets.d.ts +3 -0
  126. package/dist/src/resources/datasets.js +10 -5
  127. package/dist/src/resources/flow-zones.d.ts +2 -2
  128. package/dist/src/resources/flow-zones.js +4 -1
  129. package/dist/src/resources/meanings.d.ts +2 -0
  130. package/dist/src/resources/meanings.js +4 -0
  131. package/dist/src/resources/ml-tasks.d.ts +91 -0
  132. package/dist/src/resources/ml-tasks.js +130 -0
  133. package/dist/src/resources/model-evaluation-stores.d.ts +41 -0
  134. package/dist/src/resources/model-evaluation-stores.js +36 -0
  135. package/dist/src/resources/notebooks.d.ts +5 -7
  136. package/dist/src/resources/notebooks.js +10 -7
  137. package/dist/src/resources/projects.d.ts +1 -1
  138. package/dist/src/resources/projects.js +2 -2
  139. package/dist/src/resources/recipes.d.ts +3 -3
  140. package/dist/src/resources/recipes.js +198 -38
  141. package/dist/src/resources/saved-models.d.ts +41 -0
  142. package/dist/src/resources/saved-models.js +40 -0
  143. package/dist/src/resources/scenarios.js +67 -26
  144. package/dist/src/resources/statistics.js +9 -0
  145. package/dist/src/schemas.d.ts +2 -2
  146. package/dist/src/schemas.js +1 -1
  147. package/dist/src/skill.js +2 -2
  148. package/dist/src/utils/sanitize.js +2 -1
  149. package/package.json +1 -1
  150. package/packages/types/dist/index.d.ts +19 -2
  151. package/packages/types/dist/index.js +13 -1
@@ -0,0 +1,85 @@
1
+ import { readIfExists, skipResult, } from "../output.js";
2
+ import { requireArgs, } from "../usage.js";
3
+ export const savedModelCommands = {
4
+ list: {
5
+ handler: (c, _a, f) => c.savedModels.list(f["project-key"]),
6
+ usage: "dss saved-model list [--project-key KEY]",
7
+ description: "List saved models in a project.",
8
+ examples: ["dss saved-model list --project-key PROJECT",],
9
+ },
10
+ get: {
11
+ handler: (c, a, f) => {
12
+ requireArgs(a, 1, "dss saved-model get <modelId> [--project-key KEY]");
13
+ return c.savedModels.get(a[0], f["project-key"]);
14
+ },
15
+ usage: "dss saved-model get <modelId> [--project-key KEY]",
16
+ description: "Get a saved model.",
17
+ examples: ["dss saved-model get MODEL_ID --project-key PROJECT",],
18
+ },
19
+ "list-versions": {
20
+ handler: (c, a, f) => {
21
+ requireArgs(a, 1, "dss saved-model list-versions <modelId> [--project-key KEY]");
22
+ return c.savedModels.listVersions(a[0], f["project-key"]);
23
+ },
24
+ usage: "dss saved-model list-versions <modelId> [--project-key KEY]",
25
+ description: "List versions of a saved model.",
26
+ examples: ["dss saved-model list-versions MODEL_ID --project-key PROJECT",],
27
+ },
28
+ "version-details": {
29
+ handler: (c, a, f) => {
30
+ requireArgs(a, 2, "dss saved-model version-details <modelId> <versionId> [--project-key KEY]");
31
+ return c.savedModels.versionDetails(a[0], a[1], f["project-key"]);
32
+ },
33
+ usage: "dss saved-model version-details <modelId> <versionId> [--project-key KEY]",
34
+ description: "Get details for one saved-model version.",
35
+ examples: [
36
+ "dss saved-model version-details MODEL_ID VERSION_ID --project-key PROJECT",
37
+ ],
38
+ },
39
+ "set-active": {
40
+ handler: async (c, a, f) => {
41
+ requireArgs(a, 2, "dss saved-model set-active <modelId> <versionId> [--dry-run] [--project-key KEY]");
42
+ const projectKey = f["project-key"];
43
+ if (f["dry-run"] === true) {
44
+ return {
45
+ dryRun: true,
46
+ action: "set-active",
47
+ resource: "saved-model",
48
+ id: a[0],
49
+ versionId: a[1],
50
+ projectKey,
51
+ payload: { versionId: a[1], },
52
+ };
53
+ }
54
+ return c.savedModels.setActiveVersion(a[0], a[1], projectKey);
55
+ },
56
+ usage: "dss saved-model set-active <modelId> <versionId> [--dry-run] [--project-key KEY]",
57
+ description: "Set the active version of a saved model.",
58
+ examples: [
59
+ "dss saved-model set-active MODEL_ID VERSION_ID --project-key PROJECT",
60
+ "dss saved-model set-active MODEL_ID VERSION_ID --dry-run --project-key PROJECT",
61
+ ],
62
+ },
63
+ delete: {
64
+ handler: async (c, a, f) => {
65
+ requireArgs(a, 1, "dss saved-model delete <modelId> [--if-exists] [--dry-run] [--project-key KEY]");
66
+ const projectKey = f["project-key"];
67
+ if (f["dry-run"] === true || f["if-exists"] === true) {
68
+ const current = await readIfExists(() => c.savedModels.get(a[0], projectKey));
69
+ if (!current)
70
+ return skipResult("saved-model", a[0], "missing");
71
+ if (f["dry-run"] === true) {
72
+ return { dryRun: true, action: "delete", resource: "saved-model", id: a[0], current, };
73
+ }
74
+ }
75
+ await c.savedModels.delete(a[0], projectKey);
76
+ return { deleted: a[0], resource: "saved-model", };
77
+ },
78
+ usage: "dss saved-model delete <modelId> [--if-exists] [--dry-run] [--project-key KEY]",
79
+ description: "Delete a saved model.",
80
+ examples: [
81
+ "dss saved-model delete MODEL_ID --if-exists --project-key PROJECT",
82
+ "dss saved-model delete MODEL_ID --dry-run --project-key PROJECT",
83
+ ],
84
+ },
85
+ };
@@ -0,0 +1,2 @@
1
+ import type { CommandMeta } from "../types.js";
2
+ export declare const scenarioCommands: Record<string, CommandMeta>;
@@ -0,0 +1,190 @@
1
+ import { scenarioUpdatePreview, } from "../../resources/scenarios.js";
2
+ import { jsonInput, num, } from "../coerce.js";
3
+ import { encodedProjectEndpoint, readIfExists, skipResult, } from "../output.js";
4
+ import { requireArgs, UsageError, } from "../usage.js";
5
+ export const scenarioCommands = {
6
+ list: {
7
+ handler: (c, _a, f) => c.scenarios.list(f["project-key"]),
8
+ usage: "dss scenario list [--project-key KEY]",
9
+ description: "List all scenarios in a project.",
10
+ examples: ["dss scenario list",],
11
+ },
12
+ get: {
13
+ handler: (c, a, f) => {
14
+ requireArgs(a, 1, "dss scenario get <id>");
15
+ return c.scenarios.get(a[0], { projectKey: f["project-key"], });
16
+ },
17
+ usage: "dss scenario get <id> [--project-key KEY]",
18
+ description: "Get raw scenario definition. For step-based scenario edits, patch params.steps; rawParams.params is DSS echo data.",
19
+ examples: ["dss scenario get my_scenario",],
20
+ },
21
+ run: {
22
+ handler: async (c, a, f) => {
23
+ requireArgs(a, 1, "dss scenario run <id>");
24
+ const pk = f["project-key"];
25
+ const options = {
26
+ pollIntervalMs: num(f["poll-interval"]),
27
+ timeoutMs: num(f["timeout"]),
28
+ };
29
+ if (f["dry-run"] === true) {
30
+ return {
31
+ dryRun: true,
32
+ action: "run",
33
+ resource: "scenario",
34
+ id: a[0],
35
+ ...options,
36
+ endpoint: encodedProjectEndpoint(c, pk, `/scenarios/${encodeURIComponent(a[0])}/run/`),
37
+ method: "POST",
38
+ };
39
+ }
40
+ if (f["wait"] === true) {
41
+ return c.scenarios.runAndWait(a[0], { ...options, projectKey: pk, });
42
+ }
43
+ return c.scenarios.run(a[0], pk);
44
+ },
45
+ usage: "dss scenario run <id> [--wait] [--timeout MS] [--poll-interval MS] [--dry-run] [--project-key KEY]",
46
+ description: "Trigger a scenario run, optionally waiting for completion.",
47
+ examples: ["dss scenario run my_scenario", "dss scenario run my_scenario --wait",],
48
+ },
49
+ "run-and-wait": {
50
+ handler: async (c, a, f) => {
51
+ requireArgs(a, 1, "dss scenario run-and-wait <id>");
52
+ const pk = f["project-key"];
53
+ const options = {
54
+ pollIntervalMs: num(f["poll-interval"]),
55
+ timeoutMs: num(f["timeout"]),
56
+ };
57
+ if (f["dry-run"] === true) {
58
+ return {
59
+ dryRun: true,
60
+ action: "run-and-wait",
61
+ resource: "scenario",
62
+ id: a[0],
63
+ ...options,
64
+ endpoint: encodedProjectEndpoint(c, pk, `/scenarios/${encodeURIComponent(a[0])}/run/`),
65
+ method: "POST",
66
+ };
67
+ }
68
+ return c.scenarios.runAndWait(a[0], { ...options, projectKey: pk, });
69
+ },
70
+ usage: "dss scenario run-and-wait <id> [--timeout MS] [--poll-interval MS] [--dry-run] [--project-key KEY]",
71
+ description: "Run a scenario and wait for completion.",
72
+ examples: [
73
+ "dss scenario run-and-wait my_scenario",
74
+ "dss scenario run-and-wait my_scenario --timeout 300000",
75
+ ],
76
+ },
77
+ status: {
78
+ handler: (c, a, f) => {
79
+ requireArgs(a, 1, "dss scenario status <id>");
80
+ return c.scenarios.status(a[0], f["project-key"]);
81
+ },
82
+ usage: "dss scenario status <id> [--project-key KEY]",
83
+ description: "Get the current run status of a scenario.",
84
+ examples: ["dss scenario status my_scenario",],
85
+ },
86
+ delete: {
87
+ handler: async (c, a, f) => {
88
+ requireArgs(a, 1, "dss scenario delete <id>");
89
+ const pk = f["project-key"];
90
+ if (f["dry-run"] === true || f["if-exists"] === true) {
91
+ const current = await readIfExists(() => c.scenarios.get(a[0], { projectKey: pk, }));
92
+ if (!current)
93
+ return skipResult("scenario", a[0], "missing");
94
+ if (f["dry-run"] === true) {
95
+ return { dryRun: true, action: "delete", resource: "scenario", id: a[0], current, };
96
+ }
97
+ }
98
+ await c.scenarios.delete(a[0], pk);
99
+ return { deleted: a[0], resource: "scenario", };
100
+ },
101
+ usage: "dss scenario delete <id> [--if-exists] [--dry-run] [--project-key KEY]",
102
+ description: "Delete a scenario.",
103
+ examples: ["dss scenario delete my_scenario", "dss scenario delete my_scenario --if-exists",],
104
+ },
105
+ create: {
106
+ handler: async (c, a, f) => {
107
+ requireArgs(a, 2, "dss scenario create <id> <name>");
108
+ const pk = f["project-key"];
109
+ const payload = {
110
+ scenarioId: a[0],
111
+ name: a[1],
112
+ scenarioType: f["type"],
113
+ projectKey: pk,
114
+ };
115
+ if (f["if-not-exists"] === true || f["dry-run"] === true) {
116
+ const list = await c.scenarios.list(pk);
117
+ const existing = list.find((s) => s.id === a[0]);
118
+ if (existing && f["if-not-exists"] === true && f["dry-run"] !== true) {
119
+ return skipResult("scenario", a[0], "exists", { current: existing, });
120
+ }
121
+ if (f["dry-run"] === true) {
122
+ return {
123
+ dryRun: true,
124
+ action: "create",
125
+ resource: "scenario",
126
+ id: a[0],
127
+ payload,
128
+ ...(existing ? { current: existing, } : {}),
129
+ };
130
+ }
131
+ }
132
+ await c.scenarios.create(a[0], a[1], {
133
+ scenarioType: payload.scenarioType,
134
+ projectKey: pk,
135
+ });
136
+ return { created: a[0], name: a[1], resource: "scenario", };
137
+ },
138
+ usage: "dss scenario create <id> <name> [--type step_based|custom_python] [--if-not-exists] [--dry-run] [--project-key KEY]",
139
+ description: "Create a new scenario.",
140
+ examples: [
141
+ 'dss scenario create my_scenario "My Scenario"',
142
+ 'dss scenario create my_scenario "My Scenario" --type custom_python --dry-run',
143
+ ],
144
+ },
145
+ update: {
146
+ handler: async (c, a, f) => {
147
+ requireArgs(a, 1, "dss scenario update <id> [--data '{...}' | --data-file PATH | --stdin]");
148
+ const data = jsonInput(f);
149
+ if (data === undefined) {
150
+ throw new UsageError("--data, --data-file, or --stdin is required. Usage: dss scenario update <id> [--data '{...}' | --data-file PATH | --stdin]");
151
+ }
152
+ const pk = f["project-key"];
153
+ if (f["dry-run"] === true) {
154
+ const current = await c.scenarios.get(a[0], { projectKey: pk, });
155
+ const preview = scenarioUpdatePreview(current, data);
156
+ return {
157
+ dryRun: true,
158
+ action: "update",
159
+ resource: "scenario",
160
+ id: a[0],
161
+ canonicalEditableFields: preview.canonicalEditableFields,
162
+ normalization: preview.normalization,
163
+ normalizedData: preview.normalizedData,
164
+ changes: preview.changes,
165
+ unchangedPaths: preview.unchangedPaths,
166
+ current: preview.current,
167
+ next: preview.next,
168
+ };
169
+ }
170
+ const result = await c.scenarios.update(a[0], data, pk);
171
+ return {
172
+ updated: a[0],
173
+ resource: "scenario",
174
+ verified: result.verified,
175
+ changed: result.changes.length > 0,
176
+ canonicalEditableFields: result.canonicalEditableFields,
177
+ normalization: result.normalization,
178
+ ...(result.normalization.length > 0 ? { normalizedData: result.normalizedData, } : {}),
179
+ changes: result.changes,
180
+ unchangedPaths: result.unchangedPaths,
181
+ };
182
+ },
183
+ usage: "dss scenario update <id> [--data '{...}' | --data-file PATH | --stdin] [--dry-run] [--project-key KEY]",
184
+ description: "Update scenario settings via JSON merge; edit step-based scenario steps at params.steps, not rawParams.params.steps.",
185
+ examples: [
186
+ 'dss scenario update my_scenario --data \'{"params":{"steps":[]}}\' --dry-run',
187
+ "dss scenario update my_scenario --data-file settings.json --dry-run",
188
+ ],
189
+ },
190
+ };
@@ -0,0 +1,2 @@
1
+ import type { CommandMeta } from "../types.js";
2
+ export declare const sqlCommands: Record<string, CommandMeta>;
@@ -0,0 +1,109 @@
1
+ import { readFileSync, } from "node:fs";
2
+ import { mkdir, writeFile, } from "node:fs/promises";
3
+ import { dirname, resolve, } from "node:path";
4
+ import { readStdinText, stripUtf8Bom, } from "../coerce.js";
5
+ import { UsageError, } from "../usage.js";
6
+ const SQL_QUERY_USAGE = "dss sql query [SQL | --sql QUERY | --sql-file PATH | --sql - | --stdin] (--connection CONN | --dataset FULL_NAME) [--database DB] [--output PATH|--output-file PATH] [--preview N] [--request-timeout MS] [--project-key KEY]";
7
+ const DEFAULT_SQL_PREVIEW_ROWS = 5;
8
+ /**
9
+ * Parse `--preview N` into a non-negative row count. Rejects non-integers,
10
+ * negatives, and empty values loudly so a bad flag never silently degrades to a
11
+ * default. `--preview 0` is valid and yields an empty preview (explicit opt-out).
12
+ */
13
+ function parseSqlPreviewCount(value) {
14
+ if (typeof value !== "string") {
15
+ throw new UsageError(`--preview requires an integer value. Usage: ${SQL_QUERY_USAGE}`, "validation_failed");
16
+ }
17
+ const trimmed = value.trim();
18
+ const parsed = Number(trimmed);
19
+ if (trimmed.length === 0 || !Number.isInteger(parsed) || parsed < 0) {
20
+ throw new UsageError(`--preview must be a non-negative integer (got "${value}"). Usage: ${SQL_QUERY_USAGE}`, "validation_failed");
21
+ }
22
+ return parsed;
23
+ }
24
+ function resolveSqlInput(args, flags) {
25
+ const sources = [];
26
+ if (typeof flags["sql"] === "string") {
27
+ sources.push({
28
+ label: flags["sql"] === "-" ? "--sql -" : "--sql",
29
+ read: () => flags["sql"] === "-" ? readStdinText() : String(flags["sql"]),
30
+ });
31
+ }
32
+ if (typeof flags["sql-file"] === "string") {
33
+ sources.push({
34
+ label: "--sql-file",
35
+ read: () => readFileSync(flags["sql-file"], "utf-8"),
36
+ });
37
+ }
38
+ if (flags["stdin"] === true) {
39
+ sources.push({ label: "--stdin", read: readStdinText, });
40
+ }
41
+ if (args.length > 1) {
42
+ throw new UsageError(`Expected at most one positional SQL argument. Quote the SQL or use --sql-file/--stdin.\nUsage: ${SQL_QUERY_USAGE}`);
43
+ }
44
+ if (args[0] !== undefined) {
45
+ sources.push({ label: "positional SQL", read: () => args[0], });
46
+ }
47
+ if (sources.length === 0) {
48
+ throw new UsageError(`SQL input is required. Usage: ${SQL_QUERY_USAGE}`);
49
+ }
50
+ if (sources.length > 1) {
51
+ throw new UsageError(`Choose exactly one SQL input source: --sql, --sql-file, --stdin, or one positional SQL argument. Usage: ${SQL_QUERY_USAGE}`);
52
+ }
53
+ const query = stripUtf8Bom(sources[0].read());
54
+ if (query.trim().length === 0) {
55
+ throw new UsageError(`SQL input from ${sources[0].label} must not be empty. Usage: ${SQL_QUERY_USAGE}`);
56
+ }
57
+ return query;
58
+ }
59
+ export const sqlCommands = {
60
+ query: {
61
+ handler: async (c, a, f) => {
62
+ const connection = f["connection"];
63
+ const datasetFullName = f["dataset"];
64
+ if ((connection ? 1 : 0) + (datasetFullName ? 1 : 0) !== 1) {
65
+ throw new UsageError(`Pass exactly one of --connection or --dataset. Usage: ${SQL_QUERY_USAGE}`);
66
+ }
67
+ const outputFile = f["output"]
68
+ ?? f["output-file"];
69
+ const previewProvided = f["preview"] !== undefined;
70
+ if (previewProvided && !outputFile) {
71
+ throw new UsageError(`--preview requires --output or --output-file. Usage: ${SQL_QUERY_USAGE}`, "validation_failed");
72
+ }
73
+ const previewCount = previewProvided
74
+ ? parseSqlPreviewCount(f["preview"])
75
+ : DEFAULT_SQL_PREVIEW_ROWS;
76
+ const query = resolveSqlInput(a, f);
77
+ const result = await c.sql.query({
78
+ query,
79
+ connection,
80
+ datasetFullName,
81
+ database: f["database"],
82
+ projectKey: f["project-key"],
83
+ });
84
+ if (!outputFile)
85
+ return result;
86
+ const outputPath = resolve(outputFile);
87
+ await mkdir(dirname(outputPath), { recursive: true, });
88
+ await writeFile(outputPath, `${JSON.stringify(result, null, 2)}\n`, "utf-8");
89
+ return {
90
+ queryId: result.queryId,
91
+ schema: result.schema,
92
+ columns: result.columns ?? result.schema,
93
+ rowCount: result.rows.length,
94
+ preview: result.rows.slice(0, previewCount),
95
+ outputPath,
96
+ written: outputPath,
97
+ };
98
+ },
99
+ usage: SQL_QUERY_USAGE,
100
+ description: "Run a SQL query against a DSS connection or dataset.",
101
+ examples: [
102
+ "dss sql query 'SELECT * FROM orders LIMIT 10' --connection my_pg",
103
+ "dss sql query --sql-file query.sql --connection my_pg",
104
+ "echo 'SELECT 1' | dss sql query --stdin --dataset MYPROJ.orders",
105
+ "dss sql query --sql-file query.sql --connection my_pg --output results.json --request-timeout 120000",
106
+ "dss sql query --sql-file query.sql --connection my_pg --output results.json --preview 10",
107
+ ],
108
+ },
109
+ };
@@ -0,0 +1,2 @@
1
+ import type { CommandMeta } from "../types.js";
2
+ export declare const statisticsCommands: Record<string, CommandMeta>;
@@ -0,0 +1,165 @@
1
+ import { requiredJsonInput, } from "../coerce.js";
2
+ import { encodedProjectEndpoint, planResult, } from "../output.js";
3
+ import { requireArgs, } from "../usage.js";
4
+ const STATISTICS_PLAN_EXIT_CODES = { usage: 1, error: 2, transient: 3, };
5
+ const STATISTICS_FUTURE_PLAN_EXIT_CODES = {
6
+ ...STATISTICS_PLAN_EXIT_CODES,
7
+ longRunningFailure: 4,
8
+ };
9
+ function statisticsWorksheetsEndpoint(client, datasetName, projectKey) {
10
+ return encodedProjectEndpoint(client, projectKey, `/datasets/${encodeURIComponent(datasetName)}/statistics/worksheets/`);
11
+ }
12
+ function statisticsWorksheetEndpoint(client, datasetName, worksheetId, projectKey) {
13
+ return `${statisticsWorksheetsEndpoint(client, datasetName, projectKey)}${encodeURIComponent(worksheetId)}`;
14
+ }
15
+ function statisticsPlan(action, options) {
16
+ const asyncKind = options.asyncKind ?? "none";
17
+ return planResult("statistics", action, {
18
+ method: options.method,
19
+ endpoint: options.endpoint,
20
+ identifiers: options.identifiers,
21
+ ...(options.payload !== undefined ? { payload: options.payload, } : {}),
22
+ idempotency: "none",
23
+ asyncKind,
24
+ exitCodesOnFailure: asyncKind === "future"
25
+ ? STATISTICS_FUTURE_PLAN_EXIT_CODES
26
+ : STATISTICS_PLAN_EXIT_CODES,
27
+ plannedAndDryRun: true,
28
+ });
29
+ }
30
+ export const statisticsCommands = {
31
+ "list-worksheets": {
32
+ handler: (c, a, f) => {
33
+ requireArgs(a, 1, "dss statistics list-worksheets <dataset> [--project-key KEY]");
34
+ return c.statistics.listWorksheets(a[0], f["project-key"]);
35
+ },
36
+ usage: "dss statistics list-worksheets <dataset> [--project-key KEY]",
37
+ description: "List EDA statistics worksheets for a dataset.",
38
+ examples: ["dss statistics list-worksheets customers",],
39
+ },
40
+ "get-worksheet": {
41
+ handler: (c, a, f) => {
42
+ requireArgs(a, 2, "dss statistics get-worksheet <dataset> <worksheetId> [--project-key KEY]");
43
+ return c.statistics.getWorksheet(a[0], a[1], f["project-key"]);
44
+ },
45
+ usage: "dss statistics get-worksheet <dataset> <worksheetId> [--project-key KEY]",
46
+ description: "Get one statistics worksheet definition.",
47
+ examples: ["dss statistics get-worksheet customers ws_1",],
48
+ },
49
+ "create-worksheet": {
50
+ handler: async (c, a, f) => {
51
+ requireArgs(a, 1, "dss statistics create-worksheet <dataset> (--data JSON|--data-file PATH|--stdin) [--dry-run] [--project-key KEY]");
52
+ const body = requiredJsonInput(f, "--data, --data-file, or --stdin is required (worksheet definition).");
53
+ const projectKey = f["project-key"];
54
+ if (f["dry-run"] === true) {
55
+ return statisticsPlan("create-worksheet", {
56
+ method: "POST",
57
+ endpoint: statisticsWorksheetsEndpoint(c, a[0], projectKey),
58
+ identifiers: { dataset: a[0], },
59
+ payload: body,
60
+ });
61
+ }
62
+ return c.statistics.createWorksheet(a[0], body, projectKey);
63
+ },
64
+ usage: "dss statistics create-worksheet <dataset> (--data JSON|--data-file PATH|--stdin) [--dry-run] [--project-key KEY]",
65
+ description: "Create a statistics worksheet from a JSON definition.",
66
+ examples: [
67
+ 'dss statistics create-worksheet customers --data \'{"name":"Customer stats","dataSpec":{"inputDatasetSmartName":"customers","datasetSelection":{"partitionSelectionMethod":"ALL","maxRecords":30000,"samplingMethod":"FULL"}}}\'',
68
+ ],
69
+ },
70
+ "update-worksheet": {
71
+ handler: async (c, a, f) => {
72
+ requireArgs(a, 2, "dss statistics update-worksheet <dataset> <worksheetId> (--data JSON|--data-file PATH|--stdin) [--dry-run] [--project-key KEY]");
73
+ const body = requiredJsonInput(f, "--data, --data-file, or --stdin is required (worksheet definition).");
74
+ const projectKey = f["project-key"];
75
+ if (f["dry-run"] === true) {
76
+ return statisticsPlan("update-worksheet", {
77
+ method: "PUT",
78
+ endpoint: statisticsWorksheetEndpoint(c, a[0], a[1], projectKey),
79
+ identifiers: { dataset: a[0], worksheetId: a[1], },
80
+ payload: body,
81
+ });
82
+ }
83
+ return c.statistics.updateWorksheet(a[0], a[1], body, projectKey);
84
+ },
85
+ usage: "dss statistics update-worksheet <dataset> <worksheetId> (--data JSON|--data-file PATH|--stdin) [--dry-run] [--project-key KEY]",
86
+ description: "Replace a statistics worksheet definition.",
87
+ examples: ["dss statistics update-worksheet customers ws_1 --data-file ws.json",],
88
+ },
89
+ "delete-worksheet": {
90
+ handler: async (c, a, f) => {
91
+ requireArgs(a, 2, "dss statistics delete-worksheet <dataset> <worksheetId> [--dry-run] [--project-key KEY]");
92
+ const projectKey = f["project-key"];
93
+ if (f["dry-run"] === true) {
94
+ return statisticsPlan("delete-worksheet", {
95
+ method: "DELETE",
96
+ endpoint: statisticsWorksheetEndpoint(c, a[0], a[1], projectKey),
97
+ identifiers: { dataset: a[0], worksheetId: a[1], },
98
+ });
99
+ }
100
+ await c.statistics.deleteWorksheet(a[0], a[1], projectKey);
101
+ return { deleted: a[1], };
102
+ },
103
+ usage: "dss statistics delete-worksheet <dataset> <worksheetId> [--dry-run] [--project-key KEY]",
104
+ description: "Delete a statistics worksheet.",
105
+ examples: ["dss statistics delete-worksheet customers ws_1",],
106
+ },
107
+ "run-worksheet": {
108
+ handler: async (c, a, f) => {
109
+ requireArgs(a, 2, "dss statistics run-worksheet <dataset> <worksheetId> [--dry-run] [--project-key KEY]");
110
+ const projectKey = f["project-key"];
111
+ if (f["dry-run"] === true) {
112
+ return statisticsPlan("run-worksheet", {
113
+ method: "POST",
114
+ endpoint: `${statisticsWorksheetEndpoint(c, a[0], a[1], projectKey)}/actions/run-card`,
115
+ identifiers: { dataset: a[0], worksheetId: a[1], },
116
+ asyncKind: "future",
117
+ });
118
+ }
119
+ return c.statistics.runWorksheet(a[0], a[1], projectKey);
120
+ },
121
+ usage: "dss statistics run-worksheet <dataset> <worksheetId> [--dry-run] [--project-key KEY]",
122
+ description: "Run a statistics worksheet and return the DSS future response.",
123
+ examples: ["dss statistics run-worksheet customers ws_1",],
124
+ },
125
+ "run-card": {
126
+ handler: async (c, a, f) => {
127
+ requireArgs(a, 2, "dss statistics run-card <dataset> <worksheetId> (--data JSON|--data-file PATH|--stdin) [--dry-run] [--project-key KEY]");
128
+ const card = requiredJsonInput(f, "--data, --data-file, or --stdin is required (card settings).");
129
+ const projectKey = f["project-key"];
130
+ if (f["dry-run"] === true) {
131
+ return statisticsPlan("run-card", {
132
+ method: "POST",
133
+ endpoint: `${statisticsWorksheetEndpoint(c, a[0], a[1], projectKey)}/actions/run-card`,
134
+ identifiers: { dataset: a[0], worksheetId: a[1], },
135
+ payload: card,
136
+ asyncKind: "future",
137
+ });
138
+ }
139
+ return c.statistics.runCard(a[0], a[1], card, projectKey);
140
+ },
141
+ usage: "dss statistics run-card <dataset> <worksheetId> (--data JSON|--data-file PATH|--stdin) [--dry-run] [--project-key KEY]",
142
+ description: "Run a single card in a worksheet context.",
143
+ examples: ["dss statistics run-card customers ws_1 --data-file card.json",],
144
+ },
145
+ "run-computation": {
146
+ handler: async (c, a, f) => {
147
+ requireArgs(a, 2, "dss statistics run-computation <dataset> <worksheetId> (--data JSON|--data-file PATH|--stdin) [--dry-run] [--project-key KEY]");
148
+ const computation = requiredJsonInput(f, "--data, --data-file, or --stdin is required (computation settings).");
149
+ const projectKey = f["project-key"];
150
+ if (f["dry-run"] === true) {
151
+ return statisticsPlan("run-computation", {
152
+ method: "POST",
153
+ endpoint: `${statisticsWorksheetEndpoint(c, a[0], a[1], projectKey)}/actions/run-computation`,
154
+ identifiers: { dataset: a[0], worksheetId: a[1], },
155
+ payload: computation,
156
+ asyncKind: "future",
157
+ });
158
+ }
159
+ return c.statistics.runComputation(a[0], a[1], computation, projectKey);
160
+ },
161
+ usage: "dss statistics run-computation <dataset> <worksheetId> (--data JSON|--data-file PATH|--stdin) [--dry-run] [--project-key KEY]",
162
+ description: "Run a single computation in a worksheet context.",
163
+ examples: ["dss statistics run-computation customers ws_1 --data-file comp.json",],
164
+ },
165
+ };
@@ -0,0 +1,2 @@
1
+ import type { CommandMeta } from "../types.js";
2
+ export declare const streamingEndpointCommands: Record<string, CommandMeta>;
@@ -0,0 +1,50 @@
1
+ import { jsonInput, requiredJsonInput, } from "../coerce.js";
2
+ import { requireArgs, } from "../usage.js";
3
+ export const streamingEndpointCommands = {
4
+ list: {
5
+ handler: (c, _a, f) => c.streamingEndpoints.list(f["project-key"]),
6
+ usage: "dss streaming-endpoint list [--project-key KEY]",
7
+ description: "List streaming endpoints in a project.",
8
+ examples: ["dss streaming-endpoint list",],
9
+ },
10
+ get: {
11
+ handler: (c, a, f) => {
12
+ requireArgs(a, 1, "dss streaming-endpoint get <id> [--project-key KEY]");
13
+ return c.streamingEndpoints.getSettings(a[0], f["project-key"]);
14
+ },
15
+ usage: "dss streaming-endpoint get <id> [--project-key KEY]",
16
+ description: "Get a streaming endpoint's settings.",
17
+ examples: ["dss streaming-endpoint get my-stream",],
18
+ },
19
+ create: {
20
+ handler: (c, a, f) => {
21
+ requireArgs(a, 2, "dss streaming-endpoint create <id> <type> [--data JSON|--data-file PATH|--stdin] [--project-key KEY]");
22
+ const body = jsonInput(f) ?? {};
23
+ return c.streamingEndpoints.create(a[0], a[1], body, f["project-key"]);
24
+ },
25
+ usage: "dss streaming-endpoint create <id> <type> [--data JSON|--data-file PATH|--stdin] [--project-key KEY]",
26
+ description: "Create a streaming endpoint of the given type.",
27
+ examples: ["dss streaming-endpoint create my-stream kafka",],
28
+ },
29
+ "update-settings": {
30
+ handler: async (c, a, f) => {
31
+ requireArgs(a, 1, "dss streaming-endpoint update-settings <id> (--data JSON|--data-file PATH|--stdin) [--project-key KEY]");
32
+ const body = requiredJsonInput(f, "--data, --data-file, or --stdin is required (endpoint settings).");
33
+ await c.streamingEndpoints.updateSettings(a[0], body, f["project-key"]);
34
+ return { updated: a[0], };
35
+ },
36
+ usage: "dss streaming-endpoint update-settings <id> (--data JSON|--data-file PATH|--stdin) [--project-key KEY]",
37
+ description: "Replace a streaming endpoint's settings.",
38
+ examples: ["dss streaming-endpoint update-settings my-stream --data-file settings.json",],
39
+ },
40
+ delete: {
41
+ handler: async (c, a, f) => {
42
+ requireArgs(a, 1, "dss streaming-endpoint delete <id> [--project-key KEY]");
43
+ await c.streamingEndpoints.delete(a[0], f["project-key"]);
44
+ return { deleted: a[0], };
45
+ },
46
+ usage: "dss streaming-endpoint delete <id> [--project-key KEY]",
47
+ description: "Delete a streaming endpoint.",
48
+ examples: ["dss streaming-endpoint delete my-stream",],
49
+ },
50
+ };
@@ -0,0 +1,2 @@
1
+ import type { CommandMeta } from "../types.js";
2
+ export declare const variableCommands: Record<string, CommandMeta>;