Skip to content

Commit

Permalink
fix ci and simplify it more
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix committed Jul 3, 2024
1 parent 6ead100 commit c94a773
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 143 deletions.
38 changes: 1 addition & 37 deletions .github/workflows/main-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:

- uses: actionsx/prettier@v3
with:
# prettier CLI arguments.
args: --check .

test:
Expand Down Expand Up @@ -57,46 +56,11 @@ jobs:
echo ::group::..:: Mono Repo Tests ::..
pnpm run test
echo ::endgroup::
builds:
name: 👀 Test Standalone Builds
runs-on: ubuntu-latest
needs: [lint]
strategy:
matrix:
node: [18, 20]
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.1

- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: 📥 Download deps and builds folder by folder
run: |
rm -f package.json
rm -f pnpm-lock.yaml
rm -rf node_modules
for COMPONENT in `ls components`; do
if [ -d "components/${COMPONENT}" ]; then
echo ::group::..:: ${COMPONENT} ::..
cd components/${COMPONENT} && yarn install && yarn build && cd -;
echo ::endgroup::
fi
done
sync:
name: 🍿 Sync Doc to Crystallize
if: github.event_name == 'push' && github.ref_name == 'main'
runs-on: ubuntu-latest
needs: [lint, test, builds]
needs: [lint, test]
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.1
Expand Down
2 changes: 1 addition & 1 deletion components/import-export-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crystallize/import-export-sdk",
"version": "0.2.0",
"version": "1.0.0",
"license": "MIT",
"type": "module",
"exports": {
Expand Down
11 changes: 8 additions & 3 deletions components/import-export-sdk/src/shape/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ export const shape = (data: Shape): ShapeOperation => {
throw new Error('Missing tenantId config in API client');
}
const { query, variables } = getShapeQuery({
tenantId,
identifier: data.identifier,
});
const res = await client.nextPimApi(query, variables).then((res) => res?.shape?.get);
const res = await client.nextPimApi(query, variables).then((res) => res?.shape);
return !!res;
};

Expand Down Expand Up @@ -122,7 +121,13 @@ export const shape = (data: Shape): ShapeOperation => {

const execute = async (client: ThinClient): Promise<Shape | undefined> => {
const { query, variables, type } = await determineMutation(client);
return client.nextPimApi(query, variables).then((res) => res?.shape?.[type]);

return client.nextPimApi(query, variables).then((res) => {
if (type === 'create') {
return res?.createShape;
}
return res?.updateShape;
});
};

const enqueue = async (client: ThinClient): Promise<void> => {
Expand Down
12 changes: 5 additions & 7 deletions components/import-export-sdk/src/shape/mutations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ interface CreateProps {

const query = `
mutation CREATE_SHAPE ($input: CreateShapeInput!) {
shape {
create(input: $input) {
... on Shape {
identifier
name
type
}
createShape(input: $input) {
... on Shape {
identifier
name
type
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/import-export-sdk/src/shape/mutations/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface UpdateProps {

const query = `
mutation UPDATE_SHAPE ($identifier: String!, $input: UpdateShapeInput!) {
updateShape {
updateShape(identifier: $identifier, input: $input) {
... on Shape {
identifier
name
Expand Down
61 changes: 29 additions & 32 deletions components/import-export-sdk/src/shape/queries/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { VariablesType } from '@crystallize/js-api-client';
import { basicComponentConfigFragment, structuralComponentConfigFragment } from './fragments/shape.js';

interface GetProps {
tenantId: string;
identifier: string;
}

Expand All @@ -12,37 +11,35 @@ interface GetConfig {

const query = (config?: GetConfig) => `
query GET_SHAPE ($tenantId: ID!, $identifier: String!) {
shape {
get(tenantId: $tenantId, identifier: $identifier) {
identifier
name
type
${
config?.includeComponents
? `
components {
id
name
description
type
config {
...basicComponentConfig
...structuralComponentConfig
}
shape(identifier: $identifier) {
identifier
name
type
${
config?.includeComponents
? `
components {
id
name
description
type
config {
...basicComponentConfig
...structuralComponentConfig
}
variantComponents {
id
name
description
type
config {
...basicComponentConfig
...structuralComponentConfig
}
}
variantComponents {
id
name
description
type
config {
...basicComponentConfig
...structuralComponentConfig
}
`
: ''
}
}
`
: ''
}
}
}
Expand All @@ -58,9 +55,9 @@ const query = (config?: GetConfig) => `
`;

export const getShapeQuery = (
{ tenantId, identifier }: GetProps,
{ identifier }: GetProps,
config?: GetConfig,
): { query: string; variables: VariablesType } => ({
query: query(config),
variables: { tenantId, identifier },
variables: { identifier },
});
67 changes: 32 additions & 35 deletions components/import-export-sdk/src/shape/queries/getMany.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
import { VariablesType } from '@crystallize/js-api-client';
import { basicComponentConfigFragment, structuralComponentConfigFragment } from './fragments/shape.js';

interface GetManyProps {
tenantId: string;
}
interface GetManyProps {}

interface GetManyConfig {
includeComponents?: boolean;
}

const query = (config?: GetManyConfig) => `
query GET_MANY_SHAPES ($tenantId: ID!) {
shape {
getMany(tenantId: $tenantId) {
identifier
name
type
${
config?.includeComponents
? `
components {
id
name
description
type
config {
...basicComponentConfig
...structuralComponentConfig
}
query GET_MANY_SHAPES {
shapes {
identifier
name
type
${
config?.includeComponents
? `
components {
id
name
description
type
config {
...basicComponentConfig
...structuralComponentConfig
}
variantComponents {
id
name
description
type
config {
...basicComponentConfig
...structuralComponentConfig
}
}
variantComponents {
id
name
description
type
config {
...basicComponentConfig
...structuralComponentConfig
}
`
: ''
}
}
`
: ''
}
}
}
Expand All @@ -57,11 +54,11 @@ const query = (config?: GetManyConfig) => `
`;

export const getManyShapesQuery = (
{ tenantId }: GetManyProps,
_: GetManyProps,
config?: GetManyConfig,
): { query: string; variables: VariablesType } => {
return {
query: query(config),
variables: { tenantId },
variables: {},
};
};
21 changes: 7 additions & 14 deletions components/import-export-sdk/tests/shape/createMutation.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
import { z, ZodError } from 'zod';
import { ObjectId } from 'bson';
import { CreateShapeInput } from '@crystallize/schema';
import { ZodError } from 'zod';
import { NextPimCreateShapeInput } from '@crystallize/schema';
import { createShapeMutation } from '../../src/shape/mutations/create';
import { deepEqual, equal } from 'assert';
import { expect, it } from 'vitest';

const mockTenantId = new ObjectId().toString();

interface testCase {
name: string;
input: CreateShapeInput;
input: NextPimCreateShapeInput;
error?: ZodError;
}

const testCases: testCase[] = [
{
name: 'Returns the query and variables for a basic shape',
input: {
tenantId: mockTenantId,
name: 'Some Shape',
type: 'product',
},
},
{
name: 'Returns the query and variables for a shape with components',
input: {
tenantId: mockTenantId,
name: 'Some Shape',
type: 'product',
components: [
Expand Down Expand Up @@ -61,23 +56,21 @@ const testCases: testCase[] = [
{
name: 'Throws a validation error when structure does not match ShapeCreateInputSchema',
input: {
name: 'some invalid shape',
type: 'product',
} as CreateShapeInput,
} as NextPimCreateShapeInput,
error: new ZodError([
{
code: 'invalid_type',
expected: 'string',
received: 'undefined',
path: ['tenantId'],
path: ['name'],
message: 'Required',
},
]),
},
{
name: 'Throws a validation error when component config does not match component type',
input: {
tenantId: mockTenantId,
name: 'some invalid shape',
type: 'product',
components: [
Expand Down Expand Up @@ -127,8 +120,8 @@ testCases.forEach((tc) =>
query.replace(re, ''),
`
mutation CREATE_SHAPE ($input: CreateShapeInput!) {
shape {
create(input: $input) {
createShape(input: $input) {
... on Shape {
identifier
name
type
Expand Down
Loading

0 comments on commit c94a773

Please sign in to comment.