@constructive-sdk/cli 0.20.9 → 0.21.2

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 (45) hide show
  1. package/admin/cli/commands/usage-snapshot.d.ts +8 -0
  2. package/admin/cli/commands/usage-snapshot.js +316 -0
  3. package/admin/cli/commands.js +3 -1
  4. package/admin/cli/executor.d.ts +1 -0
  5. package/admin/orm/index.d.ts +2 -0
  6. package/admin/orm/index.js +2 -0
  7. package/admin/orm/input-types.d.ts +129 -0
  8. package/admin/orm/models/index.d.ts +1 -0
  9. package/admin/orm/models/index.js +3 -1
  10. package/admin/orm/models/usageSnapshot.d.ts +56 -0
  11. package/admin/orm/models/usageSnapshot.js +100 -0
  12. package/esm/admin/cli/commands/usage-snapshot.d.ts +8 -0
  13. package/esm/admin/cli/commands/usage-snapshot.js +314 -0
  14. package/esm/admin/cli/commands.js +3 -1
  15. package/esm/admin/cli/executor.d.ts +1 -0
  16. package/esm/admin/orm/index.d.ts +2 -0
  17. package/esm/admin/orm/index.js +2 -0
  18. package/esm/admin/orm/input-types.d.ts +129 -0
  19. package/esm/admin/orm/models/index.d.ts +1 -0
  20. package/esm/admin/orm/models/index.js +1 -0
  21. package/esm/admin/orm/models/usageSnapshot.d.ts +56 -0
  22. package/esm/admin/orm/models/usageSnapshot.js +96 -0
  23. package/esm/public/cli/commands/usage-snapshot.d.ts +8 -0
  24. package/esm/public/cli/commands/usage-snapshot.js +314 -0
  25. package/esm/public/cli/commands.js +3 -1
  26. package/esm/public/cli/executor.d.ts +1 -0
  27. package/esm/public/orm/index.d.ts +2 -0
  28. package/esm/public/orm/index.js +2 -0
  29. package/esm/public/orm/input-types.d.ts +129 -0
  30. package/esm/public/orm/models/index.d.ts +1 -0
  31. package/esm/public/orm/models/index.js +1 -0
  32. package/esm/public/orm/models/usageSnapshot.d.ts +56 -0
  33. package/esm/public/orm/models/usageSnapshot.js +96 -0
  34. package/package.json +6 -6
  35. package/public/cli/commands/usage-snapshot.d.ts +8 -0
  36. package/public/cli/commands/usage-snapshot.js +316 -0
  37. package/public/cli/commands.js +3 -1
  38. package/public/cli/executor.d.ts +1 -0
  39. package/public/orm/index.d.ts +2 -0
  40. package/public/orm/index.js +2 -0
  41. package/public/orm/input-types.d.ts +129 -0
  42. package/public/orm/models/index.d.ts +1 -0
  43. package/public/orm/models/index.js +3 -1
  44. package/public/orm/models/usageSnapshot.d.ts +56 -0
  45. package/public/orm/models/usageSnapshot.js +100 -0
@@ -661,6 +661,20 @@ export interface OrgChartEdge {
661
661
  /** Numeric seniority level for this position (higher = more senior) */
662
662
  positionLevel?: number | null;
663
663
  }
664
+ /** Periodic snapshot of a single metric for a database. Collected by the snapshot_usage() cron job in constructive-limits. Each row records one metric measurement (e.g. reads, writes, storage_bytes) at a point in time, with optional dimensions for sub-metric breakdowns. */
665
+ export interface UsageSnapshot {
666
+ /** The database this snapshot belongs to. References metaschema_public.database.id but declared without an FK constraint — the snapshot collector runs in a platform context where the FK would add overhead without value. */
667
+ databaseId?: string | null;
668
+ /** Identifier for the metric being measured (e.g. 'reads', 'writes', 'storage_bytes', 'compute_time_ms'). */
669
+ metricName?: string | null;
670
+ /** The measured value at the time of capture. Interpretation depends on metric_name (count, bytes, milliseconds, etc.). */
671
+ metricValue?: string | null;
672
+ /** Optional sub-metric breakdowns as key-value pairs (e.g. {"query_type": "select"} for reads). Empty object when no breakdown is needed. */
673
+ dimensions?: Record<string, unknown> | null;
674
+ /** When this snapshot was taken. Defaults to the current timestamp; the snapshot collector may override this for backdated imports. */
675
+ capturedAt?: string | null;
676
+ id: string;
677
+ }
664
678
  /** Per-membership profile information visible to other entity members (display name, email, title, bio, avatar) */
665
679
  export interface OrgMemberProfile {
666
680
  id: string;
@@ -1008,6 +1022,8 @@ export interface OrgGrantRelations {
1008
1022
  }
1009
1023
  export interface OrgChartEdgeRelations {
1010
1024
  }
1025
+ export interface UsageSnapshotRelations {
1026
+ }
1011
1027
  export interface OrgMemberProfileRelations {
1012
1028
  membership?: OrgMembership | null;
1013
1029
  }
@@ -1066,6 +1082,7 @@ export type AppLimitEventWithRelations = AppLimitEvent & AppLimitEventRelations;
1066
1082
  export type OrgLimitEventWithRelations = OrgLimitEvent & OrgLimitEventRelations;
1067
1083
  export type OrgGrantWithRelations = OrgGrant & OrgGrantRelations;
1068
1084
  export type OrgChartEdgeWithRelations = OrgChartEdge & OrgChartEdgeRelations;
1085
+ export type UsageSnapshotWithRelations = UsageSnapshot & UsageSnapshotRelations;
1069
1086
  export type OrgMemberProfileWithRelations = OrgMemberProfile & OrgMemberProfileRelations;
1070
1087
  export type AppLevelWithRelations = AppLevel & AppLevelRelations;
1071
1088
  export type AppLimitWithRelations = AppLimit & AppLimitRelations;
@@ -1393,6 +1410,14 @@ export type OrgChartEdgeSelect = {
1393
1410
  positionTitle?: boolean;
1394
1411
  positionLevel?: boolean;
1395
1412
  };
1413
+ export type UsageSnapshotSelect = {
1414
+ databaseId?: boolean;
1415
+ metricName?: boolean;
1416
+ metricValue?: boolean;
1417
+ dimensions?: boolean;
1418
+ capturedAt?: boolean;
1419
+ id?: boolean;
1420
+ };
1396
1421
  export type OrgMemberProfileSelect = {
1397
1422
  id?: boolean;
1398
1423
  createdAt?: boolean;
@@ -2252,6 +2277,26 @@ export interface OrgChartEdgeFilter {
2252
2277
  /** Negates the expression. */
2253
2278
  not?: OrgChartEdgeFilter;
2254
2279
  }
2280
+ export interface UsageSnapshotFilter {
2281
+ /** Filter by the object’s `databaseId` field. */
2282
+ databaseId?: UUIDFilter;
2283
+ /** Filter by the object’s `metricName` field. */
2284
+ metricName?: StringFilter;
2285
+ /** Filter by the object’s `metricValue` field. */
2286
+ metricValue?: BigIntFilter;
2287
+ /** Filter by the object’s `dimensions` field. */
2288
+ dimensions?: JSONFilter;
2289
+ /** Filter by the object’s `capturedAt` field. */
2290
+ capturedAt?: DatetimeFilter;
2291
+ /** Filter by the object’s `id` field. */
2292
+ id?: UUIDFilter;
2293
+ /** Checks for all expressions in this list. */
2294
+ and?: UsageSnapshotFilter[];
2295
+ /** Checks for any expressions in this list. */
2296
+ or?: UsageSnapshotFilter[];
2297
+ /** Negates the expression. */
2298
+ not?: UsageSnapshotFilter;
2299
+ }
2255
2300
  export interface OrgMemberProfileFilter {
2256
2301
  /** Filter by the object’s `id` field. */
2257
2302
  id?: UUIDFilter;
@@ -2628,6 +2673,7 @@ export type AppLimitEventOrderBy = 'NATURAL' | 'NAME_ASC' | 'NAME_DESC' | 'ACTOR
2628
2673
  export type OrgLimitEventOrderBy = 'NATURAL' | 'NAME_ASC' | 'NAME_DESC' | 'ACTOR_ID_ASC' | 'ACTOR_ID_DESC' | 'ENTITY_ID_ASC' | 'ENTITY_ID_DESC' | 'EVENT_TYPE_ASC' | 'EVENT_TYPE_DESC' | 'DELTA_ASC' | 'DELTA_DESC' | 'NUM_BEFORE_ASC' | 'NUM_BEFORE_DESC' | 'NUM_AFTER_ASC' | 'NUM_AFTER_DESC' | 'MAX_AT_EVENT_ASC' | 'MAX_AT_EVENT_DESC' | 'REASON_ASC' | 'REASON_DESC';
2629
2674
  export type OrgGrantOrderBy = 'NATURAL' | 'PRIMARY_KEY_ASC' | 'PRIMARY_KEY_DESC' | 'ID_ASC' | 'ID_DESC' | 'PERMISSIONS_ASC' | 'PERMISSIONS_DESC' | 'IS_GRANT_ASC' | 'IS_GRANT_DESC' | 'ACTOR_ID_ASC' | 'ACTOR_ID_DESC' | 'ENTITY_ID_ASC' | 'ENTITY_ID_DESC' | 'GRANTOR_ID_ASC' | 'GRANTOR_ID_DESC' | 'CREATED_AT_ASC' | 'CREATED_AT_DESC' | 'UPDATED_AT_ASC' | 'UPDATED_AT_DESC';
2630
2675
  export type OrgChartEdgeOrderBy = 'NATURAL' | 'PRIMARY_KEY_ASC' | 'PRIMARY_KEY_DESC' | 'ID_ASC' | 'ID_DESC' | 'CREATED_AT_ASC' | 'CREATED_AT_DESC' | 'UPDATED_AT_ASC' | 'UPDATED_AT_DESC' | 'ENTITY_ID_ASC' | 'ENTITY_ID_DESC' | 'CHILD_ID_ASC' | 'CHILD_ID_DESC' | 'PARENT_ID_ASC' | 'PARENT_ID_DESC' | 'POSITION_TITLE_ASC' | 'POSITION_TITLE_DESC' | 'POSITION_LEVEL_ASC' | 'POSITION_LEVEL_DESC';
2676
+ export type UsageSnapshotOrderBy = 'NATURAL' | 'PRIMARY_KEY_ASC' | 'PRIMARY_KEY_DESC' | 'DATABASE_ID_ASC' | 'DATABASE_ID_DESC' | 'METRIC_NAME_ASC' | 'METRIC_NAME_DESC' | 'METRIC_VALUE_ASC' | 'METRIC_VALUE_DESC' | 'DIMENSIONS_ASC' | 'DIMENSIONS_DESC' | 'CAPTURED_AT_ASC' | 'CAPTURED_AT_DESC' | 'ID_ASC' | 'ID_DESC';
2631
2677
  export type OrgMemberProfileOrderBy = 'NATURAL' | 'PRIMARY_KEY_ASC' | 'PRIMARY_KEY_DESC' | 'ID_ASC' | 'ID_DESC' | 'CREATED_AT_ASC' | 'CREATED_AT_DESC' | 'UPDATED_AT_ASC' | 'UPDATED_AT_DESC' | 'MEMBERSHIP_ID_ASC' | 'MEMBERSHIP_ID_DESC' | 'ENTITY_ID_ASC' | 'ENTITY_ID_DESC' | 'ACTOR_ID_ASC' | 'ACTOR_ID_DESC' | 'DISPLAY_NAME_ASC' | 'DISPLAY_NAME_DESC' | 'EMAIL_ASC' | 'EMAIL_DESC' | 'TITLE_ASC' | 'TITLE_DESC' | 'BIO_ASC' | 'BIO_DESC' | 'PROFILE_PICTURE_ASC' | 'PROFILE_PICTURE_DESC';
2632
2678
  export type AppLevelOrderBy = 'NATURAL' | 'PRIMARY_KEY_ASC' | 'PRIMARY_KEY_DESC' | 'ID_ASC' | 'ID_DESC' | 'NAME_ASC' | 'NAME_DESC' | 'DESCRIPTION_ASC' | 'DESCRIPTION_DESC' | 'IMAGE_ASC' | 'IMAGE_DESC' | 'OWNER_ID_ASC' | 'OWNER_ID_DESC' | 'CREATED_AT_ASC' | 'CREATED_AT_DESC' | 'UPDATED_AT_ASC' | 'UPDATED_AT_DESC';
2633
2679
  export type AppLimitOrderBy = 'NATURAL' | 'PRIMARY_KEY_ASC' | 'PRIMARY_KEY_DESC' | 'ID_ASC' | 'ID_DESC' | 'NAME_ASC' | 'NAME_DESC' | 'ACTOR_ID_ASC' | 'ACTOR_ID_DESC' | 'NUM_ASC' | 'NUM_DESC' | 'MAX_ASC' | 'MAX_DESC' | 'SOFT_MAX_ASC' | 'SOFT_MAX_DESC' | 'WINDOW_START_ASC' | 'WINDOW_START_DESC' | 'WINDOW_DURATION_ASC' | 'WINDOW_DURATION_DESC' | 'PLAN_MAX_ASC' | 'PLAN_MAX_DESC' | 'PURCHASED_CREDITS_ASC' | 'PURCHASED_CREDITS_DESC' | 'PERIOD_CREDITS_ASC' | 'PERIOD_CREDITS_DESC';
@@ -3492,6 +3538,32 @@ export interface DeleteOrgChartEdgeInput {
3492
3538
  clientMutationId?: string;
3493
3539
  id: string;
3494
3540
  }
3541
+ export interface CreateUsageSnapshotInput {
3542
+ clientMutationId?: string;
3543
+ usageSnapshot: {
3544
+ databaseId: string;
3545
+ metricName: string;
3546
+ metricValue?: string;
3547
+ dimensions?: Record<string, unknown>;
3548
+ capturedAt?: string;
3549
+ };
3550
+ }
3551
+ export interface UsageSnapshotPatch {
3552
+ databaseId?: string | null;
3553
+ metricName?: string | null;
3554
+ metricValue?: string | null;
3555
+ dimensions?: Record<string, unknown> | null;
3556
+ capturedAt?: string | null;
3557
+ }
3558
+ export interface UpdateUsageSnapshotInput {
3559
+ clientMutationId?: string;
3560
+ id: string;
3561
+ usageSnapshotPatch: UsageSnapshotPatch;
3562
+ }
3563
+ export interface DeleteUsageSnapshotInput {
3564
+ clientMutationId?: string;
3565
+ id: string;
3566
+ }
3495
3567
  export interface CreateOrgMemberProfileInput {
3496
3568
  clientMutationId?: string;
3497
3569
  orgMemberProfile: {
@@ -5978,6 +6050,51 @@ export type DeleteOrgChartEdgePayloadSelect = {
5978
6050
  select: OrgChartEdgeEdgeSelect;
5979
6051
  };
5980
6052
  };
6053
+ export interface CreateUsageSnapshotPayload {
6054
+ clientMutationId?: string | null;
6055
+ /** The `UsageSnapshot` that was created by this mutation. */
6056
+ usageSnapshot?: UsageSnapshot | null;
6057
+ usageSnapshotEdge?: UsageSnapshotEdge | null;
6058
+ }
6059
+ export type CreateUsageSnapshotPayloadSelect = {
6060
+ clientMutationId?: boolean;
6061
+ usageSnapshot?: {
6062
+ select: UsageSnapshotSelect;
6063
+ };
6064
+ usageSnapshotEdge?: {
6065
+ select: UsageSnapshotEdgeSelect;
6066
+ };
6067
+ };
6068
+ export interface UpdateUsageSnapshotPayload {
6069
+ clientMutationId?: string | null;
6070
+ /** The `UsageSnapshot` that was updated by this mutation. */
6071
+ usageSnapshot?: UsageSnapshot | null;
6072
+ usageSnapshotEdge?: UsageSnapshotEdge | null;
6073
+ }
6074
+ export type UpdateUsageSnapshotPayloadSelect = {
6075
+ clientMutationId?: boolean;
6076
+ usageSnapshot?: {
6077
+ select: UsageSnapshotSelect;
6078
+ };
6079
+ usageSnapshotEdge?: {
6080
+ select: UsageSnapshotEdgeSelect;
6081
+ };
6082
+ };
6083
+ export interface DeleteUsageSnapshotPayload {
6084
+ clientMutationId?: string | null;
6085
+ /** The `UsageSnapshot` that was deleted by this mutation. */
6086
+ usageSnapshot?: UsageSnapshot | null;
6087
+ usageSnapshotEdge?: UsageSnapshotEdge | null;
6088
+ }
6089
+ export type DeleteUsageSnapshotPayloadSelect = {
6090
+ clientMutationId?: boolean;
6091
+ usageSnapshot?: {
6092
+ select: UsageSnapshotSelect;
6093
+ };
6094
+ usageSnapshotEdge?: {
6095
+ select: UsageSnapshotEdgeSelect;
6096
+ };
6097
+ };
5981
6098
  export interface CreateOrgMemberProfilePayload {
5982
6099
  clientMutationId?: string | null;
5983
6100
  /** The `OrgMemberProfile` that was created by this mutation. */
@@ -6829,6 +6946,18 @@ export type OrgChartEdgeEdgeSelect = {
6829
6946
  select: OrgChartEdgeSelect;
6830
6947
  };
6831
6948
  };
6949
+ /** A `UsageSnapshot` edge in the connection. */
6950
+ export interface UsageSnapshotEdge {
6951
+ cursor?: string | null;
6952
+ /** The `UsageSnapshot` at the end of the edge. */
6953
+ node?: UsageSnapshot | null;
6954
+ }
6955
+ export type UsageSnapshotEdgeSelect = {
6956
+ cursor?: boolean;
6957
+ node?: {
6958
+ select: UsageSnapshotSelect;
6959
+ };
6960
+ };
6832
6961
  /** A `OrgMemberProfile` edge in the connection. */
6833
6962
  export interface OrgMemberProfileEdge {
6834
6963
  cursor?: string | null;
@@ -39,6 +39,7 @@ export { AppLimitEventModel } from './appLimitEvent';
39
39
  export { OrgLimitEventModel } from './orgLimitEvent';
40
40
  export { OrgGrantModel } from './orgGrant';
41
41
  export { OrgChartEdgeModel } from './orgChartEdge';
42
+ export { UsageSnapshotModel } from './usageSnapshot';
42
43
  export { OrgMemberProfileModel } from './orgMemberProfile';
43
44
  export { AppLevelModel } from './appLevel';
44
45
  export { AppLimitModel } from './appLimit';
@@ -39,6 +39,7 @@ export { AppLimitEventModel } from './appLimitEvent';
39
39
  export { OrgLimitEventModel } from './orgLimitEvent';
40
40
  export { OrgGrantModel } from './orgGrant';
41
41
  export { OrgChartEdgeModel } from './orgChartEdge';
42
+ export { UsageSnapshotModel } from './usageSnapshot';
42
43
  export { OrgMemberProfileModel } from './orgMemberProfile';
43
44
  export { AppLevelModel } from './appLevel';
44
45
  export { AppLimitModel } from './appLimit';
@@ -0,0 +1,56 @@
1
+ /**
2
+ * UsageSnapshot model for ORM client
3
+ * @generated by @constructive-io/graphql-codegen
4
+ * DO NOT EDIT - changes will be overwritten
5
+ */
6
+ import { OrmClient } from '../client';
7
+ import { QueryBuilder } from '../query-builder';
8
+ import type { ConnectionResult, FindManyArgs, FindFirstArgs, CreateArgs, UpdateArgs, DeleteArgs, InferSelectResult, StrictSelect } from '../select-types';
9
+ import type { UsageSnapshotWithRelations, UsageSnapshotSelect, UsageSnapshotFilter, UsageSnapshotOrderBy, CreateUsageSnapshotInput, UsageSnapshotPatch } from '../input-types';
10
+ export declare class UsageSnapshotModel {
11
+ private client;
12
+ constructor(client: OrmClient);
13
+ findMany<S extends UsageSnapshotSelect>(args: FindManyArgs<S, UsageSnapshotFilter, UsageSnapshotOrderBy> & {
14
+ select: S;
15
+ } & StrictSelect<S, UsageSnapshotSelect>): QueryBuilder<{
16
+ usageSnapshots: ConnectionResult<InferSelectResult<UsageSnapshotWithRelations, S>>;
17
+ }>;
18
+ findFirst<S extends UsageSnapshotSelect>(args: FindFirstArgs<S, UsageSnapshotFilter> & {
19
+ select: S;
20
+ } & StrictSelect<S, UsageSnapshotSelect>): QueryBuilder<{
21
+ usageSnapshots: {
22
+ nodes: InferSelectResult<UsageSnapshotWithRelations, S>[];
23
+ };
24
+ }>;
25
+ findOne<S extends UsageSnapshotSelect>(args: {
26
+ id: string;
27
+ select: S;
28
+ } & StrictSelect<S, UsageSnapshotSelect>): QueryBuilder<{
29
+ usageSnapshot: InferSelectResult<UsageSnapshotWithRelations, S> | null;
30
+ }>;
31
+ create<S extends UsageSnapshotSelect>(args: CreateArgs<S, CreateUsageSnapshotInput['usageSnapshot']> & {
32
+ select: S;
33
+ } & StrictSelect<S, UsageSnapshotSelect>): QueryBuilder<{
34
+ createUsageSnapshot: {
35
+ usageSnapshot: InferSelectResult<UsageSnapshotWithRelations, S>;
36
+ };
37
+ }>;
38
+ update<S extends UsageSnapshotSelect>(args: UpdateArgs<S, {
39
+ id: string;
40
+ }, UsageSnapshotPatch> & {
41
+ select: S;
42
+ } & StrictSelect<S, UsageSnapshotSelect>): QueryBuilder<{
43
+ updateUsageSnapshot: {
44
+ usageSnapshot: InferSelectResult<UsageSnapshotWithRelations, S>;
45
+ };
46
+ }>;
47
+ delete<S extends UsageSnapshotSelect>(args: DeleteArgs<{
48
+ id: string;
49
+ }, S> & {
50
+ select: S;
51
+ } & StrictSelect<S, UsageSnapshotSelect>): QueryBuilder<{
52
+ deleteUsageSnapshot: {
53
+ usageSnapshot: InferSelectResult<UsageSnapshotWithRelations, S>;
54
+ };
55
+ }>;
56
+ }
@@ -0,0 +1,96 @@
1
+ import { QueryBuilder, buildFindManyDocument, buildFindFirstDocument, buildCreateDocument, buildUpdateByPkDocument, buildDeleteByPkDocument, } from '../query-builder';
2
+ import { connectionFieldsMap } from '../input-types';
3
+ export class UsageSnapshotModel {
4
+ client;
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ findMany(args) {
9
+ const { document, variables } = buildFindManyDocument('UsageSnapshot', 'usageSnapshots', args.select, {
10
+ where: args?.where,
11
+ orderBy: args?.orderBy,
12
+ first: args?.first,
13
+ last: args?.last,
14
+ after: args?.after,
15
+ before: args?.before,
16
+ offset: args?.offset,
17
+ }, 'UsageSnapshotFilter', 'UsageSnapshotOrderBy', connectionFieldsMap);
18
+ return new QueryBuilder({
19
+ client: this.client,
20
+ operation: 'query',
21
+ operationName: 'UsageSnapshot',
22
+ fieldName: 'usageSnapshots',
23
+ document,
24
+ variables,
25
+ });
26
+ }
27
+ findFirst(args) {
28
+ const { document, variables } = buildFindFirstDocument('UsageSnapshot', 'usageSnapshots', args.select, {
29
+ where: args?.where,
30
+ }, 'UsageSnapshotFilter', connectionFieldsMap);
31
+ return new QueryBuilder({
32
+ client: this.client,
33
+ operation: 'query',
34
+ operationName: 'UsageSnapshot',
35
+ fieldName: 'usageSnapshots',
36
+ document,
37
+ variables,
38
+ });
39
+ }
40
+ findOne(args) {
41
+ const { document, variables } = buildFindManyDocument('UsageSnapshot', 'usageSnapshots', args.select, {
42
+ where: {
43
+ id: {
44
+ equalTo: args.id,
45
+ },
46
+ },
47
+ first: 1,
48
+ }, 'UsageSnapshotFilter', 'UsageSnapshotOrderBy', connectionFieldsMap);
49
+ return new QueryBuilder({
50
+ client: this.client,
51
+ operation: 'query',
52
+ operationName: 'UsageSnapshot',
53
+ fieldName: 'usageSnapshot',
54
+ document,
55
+ variables,
56
+ transform: (data) => ({
57
+ usageSnapshot: data.usageSnapshots?.nodes?.[0] ?? null,
58
+ }),
59
+ });
60
+ }
61
+ create(args) {
62
+ const { document, variables } = buildCreateDocument('UsageSnapshot', 'createUsageSnapshot', 'usageSnapshot', args.select, args.data, 'CreateUsageSnapshotInput', connectionFieldsMap);
63
+ return new QueryBuilder({
64
+ client: this.client,
65
+ operation: 'mutation',
66
+ operationName: 'UsageSnapshot',
67
+ fieldName: 'createUsageSnapshot',
68
+ document,
69
+ variables,
70
+ });
71
+ }
72
+ update(args) {
73
+ const { document, variables } = buildUpdateByPkDocument('UsageSnapshot', 'updateUsageSnapshot', 'usageSnapshot', args.select, args.where.id, args.data, 'UpdateUsageSnapshotInput', 'id', 'usageSnapshotPatch', connectionFieldsMap);
74
+ return new QueryBuilder({
75
+ client: this.client,
76
+ operation: 'mutation',
77
+ operationName: 'UsageSnapshot',
78
+ fieldName: 'updateUsageSnapshot',
79
+ document,
80
+ variables,
81
+ });
82
+ }
83
+ delete(args) {
84
+ const { document, variables } = buildDeleteByPkDocument('UsageSnapshot', 'deleteUsageSnapshot', 'usageSnapshot', {
85
+ id: args.where.id,
86
+ }, 'DeleteUsageSnapshotInput', args.select, connectionFieldsMap);
87
+ return new QueryBuilder({
88
+ client: this.client,
89
+ operation: 'mutation',
90
+ operationName: 'UsageSnapshot',
91
+ fieldName: 'deleteUsageSnapshot',
92
+ document,
93
+ variables,
94
+ });
95
+ }
96
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * CLI commands for UsageSnapshot
3
+ * @generated by @constructive-io/graphql-codegen
4
+ * DO NOT EDIT - changes will be overwritten
5
+ */
6
+ import { CLIOptions, Inquirerer } from 'inquirerer';
7
+ declare const _default: (argv: Partial<Record<string, unknown>>, prompter: Inquirerer, _options: CLIOptions) => Promise<void>;
8
+ export default _default;
@@ -0,0 +1,314 @@
1
+ /**
2
+ * CLI commands for UsageSnapshot
3
+ * @generated by @constructive-io/graphql-codegen
4
+ * DO NOT EDIT - changes will be overwritten
5
+ */
6
+ import { extractFirst } from 'inquirerer';
7
+ import { getClient } from '../executor';
8
+ import { coerceAnswers, parseFindFirstArgs, parseFindManyArgs, stripUndefined } from '../utils';
9
+ const fieldSchema = {
10
+ databaseId: 'uuid',
11
+ metricName: 'string',
12
+ metricValue: 'int',
13
+ dimensions: 'json',
14
+ capturedAt: 'string',
15
+ id: 'uuid',
16
+ };
17
+ const usage = '\nusage-snapshot <command>\n\nCommands:\n list List usageSnapshot records\n find-first Find first matching usageSnapshot record\n get Get a usageSnapshot by ID\n create Create a new usageSnapshot\n update Update an existing usageSnapshot\n delete Delete a usageSnapshot\n\nList Options:\n --limit <n> Max number of records to return (forward pagination)\n --last <n> Number of records from the end (backward pagination)\n --after <cursor> Cursor for forward pagination\n --before <cursor> Cursor for backward pagination\n --offset <n> Number of records to skip\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.name.equalTo foo)\n --condition.<f>.<op> Condition filter (dot-notation)\n --orderBy <values> Comma-separated ordering values (e.g. NAME_ASC,CREATED_AT_DESC)\n\nFind-First Options:\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.status.equalTo active)\n --condition.<f>.<op> Condition filter (dot-notation)\n\n --help, -h Show this help message\n';
18
+ export default async (argv, prompter, _options) => {
19
+ if (argv.help || argv.h) {
20
+ console.log(usage);
21
+ process.exit(0);
22
+ }
23
+ const { first: subcommand, newArgv } = extractFirst(argv);
24
+ if (!subcommand) {
25
+ const answer = await prompter.prompt(argv, [
26
+ {
27
+ type: 'autocomplete',
28
+ name: 'subcommand',
29
+ message: 'What do you want to do?',
30
+ options: ['list', 'find-first', 'get', 'create', 'update', 'delete'],
31
+ },
32
+ ]);
33
+ return handleTableSubcommand(answer.subcommand, newArgv, prompter);
34
+ }
35
+ return handleTableSubcommand(subcommand, newArgv, prompter);
36
+ };
37
+ async function handleTableSubcommand(subcommand, argv, prompter) {
38
+ switch (subcommand) {
39
+ case 'list':
40
+ return handleList(argv, prompter);
41
+ case 'find-first':
42
+ return handleFindFirst(argv, prompter);
43
+ case 'get':
44
+ return handleGet(argv, prompter);
45
+ case 'create':
46
+ return handleCreate(argv, prompter);
47
+ case 'update':
48
+ return handleUpdate(argv, prompter);
49
+ case 'delete':
50
+ return handleDelete(argv, prompter);
51
+ default:
52
+ console.log(usage);
53
+ process.exit(1);
54
+ }
55
+ }
56
+ async function handleList(argv, _prompter) {
57
+ try {
58
+ const defaultSelect = {
59
+ databaseId: true,
60
+ metricName: true,
61
+ metricValue: true,
62
+ dimensions: true,
63
+ capturedAt: true,
64
+ id: true,
65
+ };
66
+ const findManyArgs = parseFindManyArgs(argv, defaultSelect);
67
+ const client = getClient();
68
+ const result = await client.usageSnapshot.findMany(findManyArgs).execute();
69
+ console.log(JSON.stringify(result, null, 2));
70
+ }
71
+ catch (error) {
72
+ console.error('Failed to list records.');
73
+ if (error instanceof Error) {
74
+ console.error(error.message);
75
+ }
76
+ process.exit(1);
77
+ }
78
+ }
79
+ async function handleFindFirst(argv, _prompter) {
80
+ try {
81
+ const defaultSelect = {
82
+ databaseId: true,
83
+ metricName: true,
84
+ metricValue: true,
85
+ dimensions: true,
86
+ capturedAt: true,
87
+ id: true,
88
+ };
89
+ const findFirstArgs = parseFindFirstArgs(argv, defaultSelect);
90
+ const client = getClient();
91
+ const result = await client.usageSnapshot.findFirst(findFirstArgs).execute();
92
+ console.log(JSON.stringify(result, null, 2));
93
+ }
94
+ catch (error) {
95
+ console.error('Failed to find record.');
96
+ if (error instanceof Error) {
97
+ console.error(error.message);
98
+ }
99
+ process.exit(1);
100
+ }
101
+ }
102
+ async function handleGet(argv, prompter) {
103
+ try {
104
+ const answers = await prompter.prompt(argv, [
105
+ {
106
+ type: 'text',
107
+ name: 'id',
108
+ message: 'id',
109
+ required: true,
110
+ },
111
+ ]);
112
+ const client = getClient();
113
+ const result = await client.usageSnapshot
114
+ .findOne({
115
+ id: answers.id,
116
+ select: {
117
+ databaseId: true,
118
+ metricName: true,
119
+ metricValue: true,
120
+ dimensions: true,
121
+ capturedAt: true,
122
+ id: true,
123
+ },
124
+ })
125
+ .execute();
126
+ console.log(JSON.stringify(result, null, 2));
127
+ }
128
+ catch (error) {
129
+ console.error('Record not found.');
130
+ if (error instanceof Error) {
131
+ console.error(error.message);
132
+ }
133
+ process.exit(1);
134
+ }
135
+ }
136
+ async function handleCreate(argv, prompter) {
137
+ try {
138
+ const rawAnswers = await prompter.prompt(argv, [
139
+ {
140
+ type: 'text',
141
+ name: 'databaseId',
142
+ message: 'databaseId',
143
+ required: true,
144
+ },
145
+ {
146
+ type: 'text',
147
+ name: 'metricName',
148
+ message: 'metricName',
149
+ required: true,
150
+ },
151
+ {
152
+ type: 'text',
153
+ name: 'metricValue',
154
+ message: 'metricValue',
155
+ required: false,
156
+ skipPrompt: true,
157
+ },
158
+ {
159
+ type: 'json',
160
+ name: 'dimensions',
161
+ message: 'dimensions',
162
+ required: false,
163
+ skipPrompt: true,
164
+ },
165
+ {
166
+ type: 'text',
167
+ name: 'capturedAt',
168
+ message: 'capturedAt',
169
+ required: false,
170
+ skipPrompt: true,
171
+ },
172
+ ]);
173
+ const answers = coerceAnswers(rawAnswers, fieldSchema);
174
+ const cleanedData = stripUndefined(answers, fieldSchema);
175
+ const client = getClient();
176
+ const result = await client.usageSnapshot
177
+ .create({
178
+ data: {
179
+ databaseId: cleanedData.databaseId,
180
+ metricName: cleanedData.metricName,
181
+ metricValue: cleanedData.metricValue,
182
+ dimensions: cleanedData.dimensions,
183
+ capturedAt: cleanedData.capturedAt,
184
+ },
185
+ select: {
186
+ databaseId: true,
187
+ metricName: true,
188
+ metricValue: true,
189
+ dimensions: true,
190
+ capturedAt: true,
191
+ id: true,
192
+ },
193
+ })
194
+ .execute();
195
+ console.log(JSON.stringify(result, null, 2));
196
+ }
197
+ catch (error) {
198
+ console.error('Failed to create record.');
199
+ if (error instanceof Error) {
200
+ console.error(error.message);
201
+ }
202
+ process.exit(1);
203
+ }
204
+ }
205
+ async function handleUpdate(argv, prompter) {
206
+ try {
207
+ const rawAnswers = await prompter.prompt(argv, [
208
+ {
209
+ type: 'text',
210
+ name: 'id',
211
+ message: 'id',
212
+ required: true,
213
+ },
214
+ {
215
+ type: 'text',
216
+ name: 'databaseId',
217
+ message: 'databaseId',
218
+ required: false,
219
+ },
220
+ {
221
+ type: 'text',
222
+ name: 'metricName',
223
+ message: 'metricName',
224
+ required: false,
225
+ },
226
+ {
227
+ type: 'text',
228
+ name: 'metricValue',
229
+ message: 'metricValue',
230
+ required: false,
231
+ skipPrompt: true,
232
+ },
233
+ {
234
+ type: 'json',
235
+ name: 'dimensions',
236
+ message: 'dimensions',
237
+ required: false,
238
+ skipPrompt: true,
239
+ },
240
+ {
241
+ type: 'text',
242
+ name: 'capturedAt',
243
+ message: 'capturedAt',
244
+ required: false,
245
+ skipPrompt: true,
246
+ },
247
+ ]);
248
+ const answers = coerceAnswers(rawAnswers, fieldSchema);
249
+ const cleanedData = stripUndefined(answers, fieldSchema);
250
+ const client = getClient();
251
+ const result = await client.usageSnapshot
252
+ .update({
253
+ where: {
254
+ id: answers.id,
255
+ },
256
+ data: {
257
+ databaseId: cleanedData.databaseId,
258
+ metricName: cleanedData.metricName,
259
+ metricValue: cleanedData.metricValue,
260
+ dimensions: cleanedData.dimensions,
261
+ capturedAt: cleanedData.capturedAt,
262
+ },
263
+ select: {
264
+ databaseId: true,
265
+ metricName: true,
266
+ metricValue: true,
267
+ dimensions: true,
268
+ capturedAt: true,
269
+ id: true,
270
+ },
271
+ })
272
+ .execute();
273
+ console.log(JSON.stringify(result, null, 2));
274
+ }
275
+ catch (error) {
276
+ console.error('Failed to update record.');
277
+ if (error instanceof Error) {
278
+ console.error(error.message);
279
+ }
280
+ process.exit(1);
281
+ }
282
+ }
283
+ async function handleDelete(argv, prompter) {
284
+ try {
285
+ const rawAnswers = await prompter.prompt(argv, [
286
+ {
287
+ type: 'text',
288
+ name: 'id',
289
+ message: 'id',
290
+ required: true,
291
+ },
292
+ ]);
293
+ const answers = coerceAnswers(rawAnswers, fieldSchema);
294
+ const client = getClient();
295
+ const result = await client.usageSnapshot
296
+ .delete({
297
+ where: {
298
+ id: answers.id,
299
+ },
300
+ select: {
301
+ id: true,
302
+ },
303
+ })
304
+ .execute();
305
+ console.log(JSON.stringify(result, null, 2));
306
+ }
307
+ catch (error) {
308
+ console.error('Failed to delete record.');
309
+ if (error instanceof Error) {
310
+ console.error(error.message);
311
+ }
312
+ process.exit(1);
313
+ }
314
+ }