@graphcommerce/hygraph-cli 9.0.0-canary.115 → 9.0.0-canary.116
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/UpsertClient.js +11 -0
- package/dist/migrateHygraphCli.js +4 -37
- package/dist/migrations/index.js +11 -18
- package/package.json +5 -5
- package/src/UpsertClient.ts +11 -0
- package/src/migrateHygraphCli.ts +3 -3
- package/src/migrations/index.ts +11 -4
package/CHANGELOG.md
CHANGED
package/dist/UpsertClient.js
CHANGED
|
@@ -8,14 +8,17 @@ class UpsertClient extends management_sdk_1.Client {
|
|
|
8
8
|
super(params);
|
|
9
9
|
this.schema = schema;
|
|
10
10
|
}
|
|
11
|
+
/** @public */
|
|
11
12
|
upsertModel(data) {
|
|
12
13
|
const exists = this.schema.models.some((m) => m.apiId === data.apiId);
|
|
13
14
|
return exists ? this.createModel(data) : this.updateModel(data);
|
|
14
15
|
}
|
|
16
|
+
/** @public */
|
|
15
17
|
upsertComponent(data) {
|
|
16
18
|
const exists = this.schema.models.some((m) => m.apiId === data.apiId);
|
|
17
19
|
return exists ? this.createComponent(data) : this.updateComponent(data);
|
|
18
20
|
}
|
|
21
|
+
/** @public */
|
|
19
22
|
upsertSimpleField(data) {
|
|
20
23
|
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
21
24
|
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
@@ -28,39 +31,47 @@ class UpsertClient extends management_sdk_1.Client {
|
|
|
28
31
|
// const exists = model?.fields.some((f) => f.apiId === data.apiId)
|
|
29
32
|
// return exists ? this.createRemoteField(data) : this.updateRemoteField(data)
|
|
30
33
|
// }
|
|
34
|
+
/** @public */
|
|
31
35
|
upsertRelationalField(data) {
|
|
32
36
|
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
33
37
|
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
34
38
|
return exists ? this.createRelationalField(data) : this.updateRelationalField(data);
|
|
35
39
|
}
|
|
40
|
+
/** @public */
|
|
36
41
|
upsertUnionField(data) {
|
|
37
42
|
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
38
43
|
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
39
44
|
return exists ? this.createUnionField(data) : this.updateUnionField(data);
|
|
40
45
|
}
|
|
46
|
+
/** @public */
|
|
41
47
|
upsertComponentField(data) {
|
|
42
48
|
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
43
49
|
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
44
50
|
return exists ? this.createComponentField(data) : this.updateComponentField(data);
|
|
45
51
|
}
|
|
52
|
+
/** @public */
|
|
46
53
|
upsertComponentUnionField(data) {
|
|
47
54
|
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
48
55
|
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
49
56
|
return exists ? this.createComponentUnionField(data) : this.updateComponentUnionField(data);
|
|
50
57
|
}
|
|
58
|
+
/** @public */
|
|
51
59
|
upsertEnumeration(data) {
|
|
52
60
|
const exists = this.schema.enumerations.some((e) => e.apiId === data.apiId);
|
|
53
61
|
return exists ? this.createEnumeration(data) : this.updateEnumeration(data);
|
|
54
62
|
}
|
|
63
|
+
/** @public */
|
|
55
64
|
upsertEnumerableField(data) {
|
|
56
65
|
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
57
66
|
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
58
67
|
return exists ? this.createEnumerableField(data) : this.updateEnumerableField(data);
|
|
59
68
|
}
|
|
69
|
+
/** @public */
|
|
60
70
|
upsertStage(data) {
|
|
61
71
|
const exists = this.schema.stages.some((m) => m.apiId === data.apiId);
|
|
62
72
|
return exists ? this.createStage(data) : this.updateStage(data);
|
|
63
73
|
}
|
|
74
|
+
/** @public */
|
|
64
75
|
upsertLocale(data) {
|
|
65
76
|
const exists = this.schema.locales.some((m) => m.apiId === data.apiId);
|
|
66
77
|
return exists ? this.createLocale(data) : this.updateLocale(data);
|
|
@@ -1,49 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
6
|
exports.migrateHygraphCli = migrateHygraphCli;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
40
8
|
const next_config_1 = require("@graphcommerce/next-config");
|
|
41
9
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
42
|
-
const fs_1 = __importDefault(require("fs"));
|
|
43
10
|
const prompts_1 = __importDefault(require("prompts"));
|
|
44
|
-
const
|
|
45
|
-
const availableMigrations = __importStar(require("./migrations"));
|
|
11
|
+
const migrations_1 = require("./migrations");
|
|
46
12
|
const readSchema_1 = require("./readSchema");
|
|
13
|
+
const UpsertClient_1 = require("./UpsertClient");
|
|
47
14
|
const getConfig_1 = require("./utils/getConfig");
|
|
48
15
|
const getEndpointUrl_1 = require("./utils/getEndpointUrl");
|
|
49
16
|
const getManagementClient_1 = require("./utils/getManagementClient");
|
|
@@ -64,7 +31,7 @@ async function migrateHygraphCli() {
|
|
|
64
31
|
const schemaViewer = await (0, readSchema_1.readSchema)(mangementClient, hygraphConfig.projectId);
|
|
65
32
|
const schema = schemaViewer.viewer.project.environment.contentModel;
|
|
66
33
|
// A list of possible migrations
|
|
67
|
-
const possibleMigrations = Object.entries(availableMigrations);
|
|
34
|
+
const possibleMigrations = Object.entries(migrations_1.availableMigrations);
|
|
68
35
|
// Here we setup the list we ask the user to choose from
|
|
69
36
|
const selectMigrationInput = {
|
|
70
37
|
type: 'select',
|
package/dist/migrations/index.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
exports.availableMigrations = void 0;
|
|
4
|
+
const graphcommerce5to6_1 = require("./graphcommerce5to6");
|
|
5
|
+
const graphcommerce6to7_1 = require("./graphcommerce6to7");
|
|
6
|
+
const graphcommerce7to8_1 = require("./graphcommerce7to8");
|
|
7
|
+
const graphcommerce8to9_1 = require("./graphcommerce8to9");
|
|
8
|
+
exports.availableMigrations = [
|
|
9
|
+
graphcommerce5to6_1.graphcommerce5to6,
|
|
10
|
+
graphcommerce6to7_1.graphcommerce6to7,
|
|
11
|
+
graphcommerce7to8_1.graphcommerce7to8,
|
|
12
|
+
graphcommerce8to9_1.graphcommerce8to9,
|
|
13
|
+
];
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/hygraph-cli",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.0.0-canary.
|
|
5
|
+
"version": "9.0.0-canary.116",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "tsc --preserveWatchOutput --watch",
|
|
8
8
|
"build": "tsc",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@apollo/client": "*",
|
|
23
|
-
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.
|
|
24
|
-
"@graphcommerce/next-config": "^9.0.0-canary.
|
|
25
|
-
"@graphcommerce/prettier-config-pwa": "^9.0.0-canary.
|
|
26
|
-
"@graphcommerce/typescript-config-pwa": "^9.0.0-canary.
|
|
23
|
+
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.116",
|
|
24
|
+
"@graphcommerce/next-config": "^9.0.0-canary.116",
|
|
25
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.0-canary.116",
|
|
26
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.0-canary.116",
|
|
27
27
|
"dotenv": "^16.1.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
package/src/UpsertClient.ts
CHANGED
|
@@ -28,16 +28,19 @@ export class UpsertClient extends Client {
|
|
|
28
28
|
super(params)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/** @public */
|
|
31
32
|
upsertModel(data: BatchMigrationCreateModelInput) {
|
|
32
33
|
const exists = this.schema.models.some((m) => m.apiId === data.apiId)
|
|
33
34
|
return exists ? this.createModel(data) : this.updateModel(data)
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
/** @public */
|
|
36
38
|
upsertComponent(data: BatchMigrationCreateComponentInput) {
|
|
37
39
|
const exists = this.schema.models.some((m) => m.apiId === data.apiId)
|
|
38
40
|
return exists ? this.createComponent(data) : this.updateComponent(data)
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
/** @public */
|
|
41
44
|
upsertSimpleField(data: BatchMigrationCreateSimpleFieldInput) {
|
|
42
45
|
const model = this.schema.models.find((m) => m.apiId === data.parentApiId)
|
|
43
46
|
const exists = model?.fields.some((f) => f.apiId === data.apiId)
|
|
@@ -52,46 +55,54 @@ export class UpsertClient extends Client {
|
|
|
52
55
|
// return exists ? this.createRemoteField(data) : this.updateRemoteField(data)
|
|
53
56
|
// }
|
|
54
57
|
|
|
58
|
+
/** @public */
|
|
55
59
|
upsertRelationalField(data: BatchMigrationCreateRelationalFieldInput) {
|
|
56
60
|
const model = this.schema.models.find((m) => m.apiId === data.parentApiId)
|
|
57
61
|
const exists = model?.fields.some((f) => f.apiId === data.apiId)
|
|
58
62
|
return exists ? this.createRelationalField(data) : this.updateRelationalField(data)
|
|
59
63
|
}
|
|
60
64
|
|
|
65
|
+
/** @public */
|
|
61
66
|
upsertUnionField(data: BatchMigrationCreateUnionFieldInput) {
|
|
62
67
|
const model = this.schema.models.find((m) => m.apiId === data.parentApiId)
|
|
63
68
|
const exists = model?.fields.some((f) => f.apiId === data.apiId)
|
|
64
69
|
return exists ? this.createUnionField(data) : this.updateUnionField(data)
|
|
65
70
|
}
|
|
66
71
|
|
|
72
|
+
/** @public */
|
|
67
73
|
upsertComponentField(data: BatchMigrationCreateComponentFieldInput) {
|
|
68
74
|
const model = this.schema.models.find((m) => m.apiId === data.parentApiId)
|
|
69
75
|
const exists = model?.fields.some((f) => f.apiId === data.apiId)
|
|
70
76
|
return exists ? this.createComponentField(data) : this.updateComponentField(data)
|
|
71
77
|
}
|
|
72
78
|
|
|
79
|
+
/** @public */
|
|
73
80
|
upsertComponentUnionField(data: BatchMigrationCreateComponentUnionFieldInput) {
|
|
74
81
|
const model = this.schema.models.find((m) => m.apiId === data.parentApiId)
|
|
75
82
|
const exists = model?.fields.some((f) => f.apiId === data.apiId)
|
|
76
83
|
return exists ? this.createComponentUnionField(data) : this.updateComponentUnionField(data)
|
|
77
84
|
}
|
|
78
85
|
|
|
86
|
+
/** @public */
|
|
79
87
|
upsertEnumeration(data: BatchMigrationCreateEnumerationInput) {
|
|
80
88
|
const exists = this.schema.enumerations.some((e) => e.apiId === data.apiId)
|
|
81
89
|
return exists ? this.createEnumeration(data) : this.updateEnumeration(data)
|
|
82
90
|
}
|
|
83
91
|
|
|
92
|
+
/** @public */
|
|
84
93
|
upsertEnumerableField(data: BatchMigrationCreateEnumerableFieldInput) {
|
|
85
94
|
const model = this.schema.models.find((m) => m.apiId === data.parentApiId)
|
|
86
95
|
const exists = model?.fields.some((f) => f.apiId === data.apiId)
|
|
87
96
|
return exists ? this.createEnumerableField(data) : this.updateEnumerableField(data)
|
|
88
97
|
}
|
|
89
98
|
|
|
99
|
+
/** @public */
|
|
90
100
|
upsertStage(data: BatchMigrationCreateStageInput) {
|
|
91
101
|
const exists = this.schema.stages.some((m) => m.apiId === data.apiId)
|
|
92
102
|
return exists ? this.createStage(data) : this.updateStage(data)
|
|
93
103
|
}
|
|
94
104
|
|
|
105
|
+
/** @public */
|
|
95
106
|
upsertLocale(data: BatchMigrationCreateLocaleInput) {
|
|
96
107
|
const exists = this.schema.locales.some((m) => m.apiId === data.apiId)
|
|
97
108
|
return exists ? this.createLocale(data) : this.updateLocale(data)
|
package/src/migrateHygraphCli.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
1
2
|
import { loadConfig } from '@graphcommerce/next-config'
|
|
2
3
|
import dotenv from 'dotenv'
|
|
3
|
-
import fs from 'fs'
|
|
4
4
|
import type { PromptObject } from 'prompts'
|
|
5
5
|
import prompts from 'prompts'
|
|
6
|
-
import {
|
|
7
|
-
import * as availableMigrations from './migrations'
|
|
6
|
+
import { availableMigrations } from './migrations'
|
|
8
7
|
import { readSchema } from './readSchema'
|
|
9
8
|
import type { MigrationFunction, Schema } from './types'
|
|
9
|
+
import { UpsertClient } from './UpsertClient'
|
|
10
10
|
import { getConfig } from './utils/getConfig'
|
|
11
11
|
import { getEnvironment } from './utils/getEndpointUrl'
|
|
12
12
|
import { getManagementClient } from './utils/getManagementClient'
|
package/src/migrations/index.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { graphcommerce5to6 } from './graphcommerce5to6'
|
|
2
|
+
import { graphcommerce6to7 } from './graphcommerce6to7'
|
|
3
|
+
import { graphcommerce7to8 } from './graphcommerce7to8'
|
|
4
|
+
import { graphcommerce8to9 } from './graphcommerce8to9'
|
|
5
|
+
|
|
6
|
+
export const availableMigrations = [
|
|
7
|
+
graphcommerce5to6,
|
|
8
|
+
graphcommerce6to7,
|
|
9
|
+
graphcommerce7to8,
|
|
10
|
+
graphcommerce8to9,
|
|
11
|
+
]
|