Skip to content

Commit

Permalink
Merge pull request #15 from jharlow/feat-publish-workflow-2
Browse files Browse the repository at this point in the history
feat publish workflow 2
  • Loading branch information
jharlow authored Oct 12, 2024
2 parents 55106c1 + fef3401 commit 4ace752
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 70 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/main-merge.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PR Checks
name: Merge into main checks
on:
push:
branches: [main]
Expand Down Expand Up @@ -49,6 +49,11 @@ jobs:
with:
node-version: "20"
cache: "pnpm"
- uses: JS-DevTools/npm-publish@v3
- name: Install packages
run: pnpm install
- name: Run build command
run: pnpm build
- name: Publish to npm 🚀
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
dist
lib
coverage
dynamodb-local-metadata.json
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Auto-generate `dynamodb-onetable` model schemas using `zod`, with best-in-class
- Convert `zod` _objects_ into `dynamo-onetable` model schemas
- Convert `zod` _schemas_ into `dynamo-onetable` model field schemas
- Get dynamic autocomplete as you expect from `dynamo-onetable` via type-fu 🥋
- Un-representable data-types cause errors, un-representable checks optionally `debug` log
- Un-representable data-types cause errors, un-representable checks will notify you via `logger.debug` if you provide a Winston instance
- Zero dependencies

## Rationale
Expand All @@ -33,10 +33,10 @@ const accountSchema = z.object({
});
```

Defining a `Account` model is now easy. We'll extend it to include our table's indexes and pass it to `createModelSchema`.
Defining a `Account` model is now easy. We'll extend it to include our table's indexes and pass it to `zodOneModelSchema`.

```ts
import { createModelSchema } from "zod-to-dynamodb-onetable-schema";
import { zodOneModelSchema } from "zod-to-dynamodb-onetable-schema";
import { Table } from "dynamodb-onetable";

const accountRecordSchema = accountSchema.extend({
Expand All @@ -48,7 +48,7 @@ const table = new Table({
// other fields collapsed,
schema: {
indexes: { primary: { hash: "pk", sort: "sk" } },
models: { Account: createModelSchema(accountRecordSchema, {}) },
models: { Account: zodOneModelSchema(accountRecordSchema) },
},
});
```
Expand Down Expand Up @@ -76,7 +76,7 @@ Notice we didn't need to specify the `pk` or `pk`? That's because `Table` handle

```ts
import { Table } from "dynamodb-onetable";
import { createModelSchema } from "zod-to-dynamodb-onetable-schema";
import { zodOneModelSchema } from "zod-to-dynamodb-onetable-schema";
import { z } from "zod";

const accountRecordSchema = z.object({
Expand All @@ -91,7 +91,7 @@ const table = new Table({
// other fields collapsed,
schema: {
indexes: { primary: { hash: "pk", sort: "sk" } },
models: { Account: createModelSchema(accountRecordSchema, {}) },
models: { Account: zodOneModelSchema(accountRecordSchema) },
},
});

Expand All @@ -116,9 +116,9 @@ expect(newAccount).toMatchObject(storedAccount);

I appreciate any contributions, issues or discussions. My aim is to make contributing quick and easy.

Please note that PR quality checks enforce a 100% code coverage rate and will test your code against a local version of DynamoDB. Passing these requirements are essential to getting a merge/release. For new code, at least some tests should interface with an instance of `Table` that interacts with a local DynamoDB instance. An example of this test type is at `tests/createModelSchema.spec.ts`.
Please note that PR quality checks enforce a 100% code coverage rate and will test your code against a local version of DynamoDB. Passing these requirements are essential to getting a merge/release. For new code, at least some tests should interface with an instance of `Table` that interacts with a local DynamoDB instance. An example of this test type is at `tests/zodOneModelSchema.spec.ts`.

Here's a quick start to getting this repo running on your own machine (assumes you already have `gh`, `node` and `docker` installed):
Here's a quick start to getting this repo running on your own machine (assumes you already have `gh`, `node`, `pnpm` and `docker` installed):

1. Clone the repo to your own machine

Expand All @@ -143,3 +143,9 @@ pnpm install
```sh
pnpm test
```

5. Before pushing, check your work will pass checks:

```sh
pnpm pr-checks
```
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zod-to-dynamodb-onetable-schema",
"version": "0.0.0",
"version": "0.0.3",
"description": "Auto-generate `dynamodb-onetable` model schemas using `zod`, with best-in-class autocomplete",
"keywords": [
"dynamo",
Expand All @@ -14,24 +14,26 @@
"type": "git",
"url": "git+https://github.com/jharlow/zod-to-dynamodb-onetable-schema.git"
},
"homepage": "https://github.com/jharlow/zod-to-dynamodb-onetable-schema",
"bugs": {
"url": "httckaps://github.com/jharlow/zod-to-dynamodb-onetable-schema/issues"
},
"homepage": "https://github.com/jharlow/zod-to-dynamodb-onetable-schema",
"main": "index.ts",
"exports": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib/**/*"
"lib",
"README.md",
"package.json"
],
"type": "module",
"exports": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"build": "tsc",
"clean": "tsc --build --clean && rm -rf lib",
"lint": "eslint src",
"lint-fix": "eslint src --fix",
"test": "vitest",
"coverage": "vitest run --coverage"
"coverage": "vitest run --coverage",
"pr-checks": "pnpm lint && pnpm build && pnpm test && pnpm coverage"
},
"devDependencies": {
"@aws-sdk/client-dynamodb": "^3.668.0",
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,15 @@ const getConverterFunction = <T extends ZodSchema>(
export const convertZodSchemaToField = <T extends ZodSchema>(
zodSchema: T,
ref: Ref,
opts: Opts,
opts?: Opts,
): ZodToOneField<T> => {
const converterFunction = getConverterFunction(zodSchema);
return converterFunction(zodSchema, ref, opts);
return converterFunction(zodSchema, ref, opts ?? {});
};

// TODO: Add zod to name
export const createModelSchema = <T extends ZodRawShape>(
export const zodOneModelSchema = <T extends ZodRawShape>(
zodSchema: ZodObject<T>,
opts: Opts,
opts?: Opts,
): ZodObjectOneFieldSchema<T> => {
return Object.entries(zodSchema._def.shape()).reduce(
(acc, [propName, zodSchema]) => {
Expand All @@ -116,5 +115,6 @@ export const createModelSchema = <T extends ZodRawShape>(
);
};

export type { ZodToOneField };

// TODO: Replace strings with constructors
// TODO: GHA publish pipeline
42 changes: 0 additions & 42 deletions src/playground.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeAll, afterAll } from "vitest";
import { Table } from "dynamodb-onetable";
import { createModelSchema } from "../src";
import { zodOneModelSchema } from "../src";
import { z } from "zod";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { vi } from "vitest";
Expand Down Expand Up @@ -51,7 +51,7 @@ const exampleModelSchema = exampleEntitySchema.extend({
});

const schema = makeZodSchema({
Example: createModelSchema(exampleModelSchema, {}),
Example: zodOneModelSchema(exampleModelSchema),
});

const tableConstructorParams: [
Expand Down Expand Up @@ -81,7 +81,7 @@ const tableConstructorParams: [
];

describe.each(tableConstructorParams)(
"createModelSchema %s",
"zodOneModelSchema %s",
(_, tableConstructorParams) => {
const table = new Table(tableConstructorParams);

Expand Down
3 changes: 2 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig } from "vitest/config";
import { configDefaults, defineConfig } from "vitest/config";

export default defineConfig({
test: {
Expand All @@ -10,6 +10,7 @@ export default defineConfig({
branches: 100,
statements: 100,
},
exclude: configDefaults.coverage.exclude?.concat(["<rootDir>/../lib/**"]),
},
},
});

0 comments on commit 4ace752

Please sign in to comment.