Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add format check in GHA script #44

Merged
merged 6 commits into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -5,13 +5,12 @@ name: Node.js CI

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:

runs-on: ubuntu-latest

strategy:
@@ -20,12 +19,13 @@ jobs:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: make build
- run: make test
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: make format-check
- run: make build # also ensures typechecking passes
- run: make test
44 changes: 23 additions & 21 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -83,12 +83,12 @@ This project uses a few tools to help with building and packaging it up: `typesc
Their respective configuration files work together to produce the the library and this section contains a few highlights to
help better understand how it works.

* Compiled and bundled up code lives in `dist/` (set in `tsconfig.json` "outDir")
* We're targeting ES2022 as our output language, which is supprted by Node 18+ (see `tsconfig.json` "target")
* We're building both ESM (.js) and CJS (.cjs) compatible artifacts (see `tsup.config.ts` "formats")
* During build we're generating TypeScript declaration files and making them available to package consumers (see `tsup.config.ts` "dts")
* Our package uses conditional exports so that the consumer will automatically get the right ESM or CJS based on how they import (see `package.json` "exports")
* When we publish the package to NPM we're only including the `dist/`, `src/` and "default files", eg. `README`, `LICENCE` (see `package.json` "files")
- Compiled and bundled up code lives in `dist/` (set in `tsconfig.json` "outDir")
- We're targeting ES2022 as our output language, which is supprted by Node 18+ (see `tsconfig.json` "target")
- We're building both ESM (.js) and CJS (.cjs) compatible artifacts (see `tsup.config.ts` "formats")
- During build we're generating TypeScript declaration files and making them available to package consumers (see `tsup.config.ts` "dts")
- Our package uses conditional exports so that the consumer will automatically get the right ESM or CJS based on how they import (see `package.json` "exports")
- When we publish the package to NPM we're only including the `dist/`, `src/` and "default files", eg. `README`, `LICENCE` (see `package.json` "files")

## Versioning

@@ -99,35 +99,37 @@ incorporate information about the API version and SDK version. We update version
The version string looks like the following:

```js
`${major}${version}.${minor}.${patch}`
`${major}${version}.${minor}.${patch}`;
```

* `major` is set manually and is the MAJOR version of the SDK code
* `version` is a date string (`yyyymmdd`) we use as the API Version (from our OpenAPI schema)
* `minor` is set manually and is the MINOR version of the SDK code
* `patch` is set manually and is the PATCH version of the SDK code
- `major` is set manually and is the MAJOR version of the SDK code
- `version` is a date string (`yyyymmdd`) we use as the API Version (from our OpenAPI schema)
- `minor` is set manually and is the MINOR version of the SDK code
- `patch` is set manually and is the PATCH version of the SDK code

The version of the SDK should be updated in branches being merged into `main` according to the semantic versioning scheme:

* MAJOR version when you make incompatible API changes
* MINOR version when you add functionality in a backward compatible manner
* PATCH version when you make backward compatible bug fixes
- MAJOR version when you make incompatible API changes
- MINOR version when you add functionality in a backward compatible manner
- PATCH version when you make backward compatible bug fixes

### Updating The Package Version

After making changes, you should:
* Make sure to bump the `SDK_VERSION` in the `bin/update-version.ts` script
* Then run `make update-version` to ensure the `package.json` and `src/version.ts` are set correctly.

- Make sure to bump the `SDK_VERSION` in the `bin/update-version.ts` script
- Then run `make update-version` to ensure the `package.json` and `src/version.ts` are set correctly.

**NOTE:** The `make update-version` task will run after every `make sync-codegen` too!

## Releasing

**Prerequisites**:
* Have an [npmjs.com](https://www.npmjs.com/) account and it must be a member of our organization
* Have an GitHub account and it must be a member of our organization with write permissions on the repo
* The changes that are currently in the branch are the one you would like to release (typically `main`)
* The `version` field in the `package.json` is the one you would like to use for the release already

- Have an [npmjs.com](https://www.npmjs.com/) account and it must be a member of our organization
- Have an GitHub account and it must be a member of our organization with write permissions on the repo
- The changes that are currently in the branch are the one you would like to release (typically `main`)
- The `version` field in the `package.json` is the one you would like to use for the release already

**Production Releases**:

@@ -139,7 +141,7 @@ that we'd like to publish.
2. Publish to NPM & push tag to GitHub: `make publish`
3. Create new Release on GitHub (using the web UI). Add release notes, mentions, etc.

**Non-Production Releases**
**Non-Production Releases**

The previous workflow assumes that the tag being published should be marked as `latest` for the NPM
[distribution tag](https://docs.npmjs.com/adding-dist-tags-to-packages). If you would like to mark a release as
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -26,9 +26,13 @@ sync-codegen: ensure
bin/sync-codegen.ts
make update-version

.PHONY: typecheck
typecheck: ensure
npx tsc -noEmit
.PHONY: format-check
format-check: ensure
npx prettier . --check

.PHONY: format-fix
format-fix: ensure
npx prettier . --write

.PHONY: build
build: ensure
1 change: 0 additions & 1 deletion bin/update-version.ts
Original file line number Diff line number Diff line change
@@ -24,4 +24,3 @@ try {
} catch (error) {
console.error("Error reading or parsing openapi.json:", error);
}

7 changes: 4 additions & 3 deletions examples/re-running-nodes.ts
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@ const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"];
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });

const a = new GenerateText({
prompt: "in very few words describe an incredible moment in sports history, be extremely concise",
prompt:
"in very few words describe an incredible moment in sports history, be extremely concise",
});

a.result().then((result) => {
@@ -40,7 +41,7 @@ console.log("[3]", await f1);
// when we access it's result again, we will get the same
// value we had in `f1`
let f2 = a.future.text.result();
console.log("[4]", "await f1 === await f2 =", await f1 === await f2); // true
console.log("[4]", "await f1 === await f2 =", (await f1) === (await f2)); // true

// now let's run the node again
await substrate.run(a);
@@ -51,7 +52,7 @@ console.log("[5]", "Running node a second time!");
// and it should be different than the first
let f3 = a.future.text.result();
console.log("[6]", await f3);
console.log("[7]", "await f1 !== await f3 =", await f1 !== await f3); // true
console.log("[7]", "await f1 !== await f3 =", (await f1) !== (await f3)); // true

// if we look back at the previous results we should see
// that the first two are still the same, but the third
1 change: 0 additions & 1 deletion examples/single.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ const a = new GenerateText({
"in very few words describe an incredible historcal technical achievement",
});


substrate.run(a);

console.log(await a.future.text.result());
4 changes: 3 additions & 1 deletion examples/string-concat.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,9 @@ const substrate = new Substrate({
baseUrl: "https://api-staging.substrate.run",
});

const a = new GenerateText({ prompt: "name a random capital city: <city name>, <country>" });
const a = new GenerateText({
prompt: "name a random capital city: <city name>, <country>",
});

const concatenated = sb.concat("tell me about visiting ", a.future.text);

14 changes: 9 additions & 5 deletions src/Mailbox.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import { Node } from "substrate/Node";
*/

/** @private */
class SubstrateEvent extends Event {};
class SubstrateEvent extends Event {}

/** @private Event that reprepresents a new server response. */
export class RequestCompleted extends SubstrateEvent {
@@ -47,19 +47,23 @@ export class Mailbox extends EventTarget {
// When we receive an event, we'll resolve this Promise
resolve(e.value.getNodeResponse(node));
// Then we'll remove the event listeners to make sure there these references in the promise go away
this.removeEventListener(RequestCompleted.type, handleRequestCompleted);
this.removeEventListener(
RequestCompleted.type,
handleRequestCompleted,
);
// We'll move this reference over to the results list
if (this.pending.length) this.resolved.push(this.pending.pop() as Promise<any>);
if (this.pending.length)
this.resolved.push(this.pending.pop() as Promise<any>);
// Finally we'll start up a new listener
waitForResponse();
}
},
};

// We attach the above listener to this Mailbox
this.addEventListener(RequestCompleted.type, handleRequestCompleted);
});
this.pending.push(p);
}
};
waitForResponse();
}

542 changes: 407 additions & 135 deletions src/Nodes.ts

Large diffs are not rendered by default.

598 changes: 298 additions & 300 deletions src/OpenAPI.ts

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions src/Platform.ts
Original file line number Diff line number Diff line change
@@ -25,7 +25,13 @@ type Browser = "ie" | "edge" | "chrome" | "firefox" | "safari";
type PlatformProperties = {
os: PlatformName;
arch: Arch;
runtime: "node" | "deno" | "edge" | "workerd" | `browser:${Browser}` | "unknown";
runtime:
| "node"
| "deno"
| "edge"
| "workerd"
| `browser:${Browser}`
| "unknown";
runtimeVersion: string;
};

@@ -64,7 +70,10 @@ export const getPlatformProperties = (): PlatformProperties => {
}

// https://developers.cloudflare.com/workers/runtime-apis/web-standards/#navigatoruseragent
if (typeof navigator !== undefined && navigator.userAgent === "Cloudflare-Workers") {
if (
typeof navigator !== undefined &&
navigator.userAgent === "Cloudflare-Workers"
) {
return {
os: "Unknown",
arch: "unknown",
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* ꩜ Substrate TypeScript SDK
* @generated file
* 20240315.20240321
*/
* ꩜ Substrate TypeScript SDK
* @generated file
* 20240315.20240321
*/

export { SubstrateError } from "substrate/Error";
export {
@@ -25,9 +25,9 @@ export {
MultiEmbedText,
EmbedImage,
MultiEmbedImage,
} from "substrate/Nodes";
} from "substrate/Nodes";

export { sb } from "substrate/sb";
export { Substrate };
import { Substrate } from "substrate/Substrate";
export default Substrate;
export default Substrate;
44 changes: 22 additions & 22 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -3,44 +3,44 @@
/* Visit https://aka.ms/tsconfig to read more about this file */

/* Language and Environment */
"target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */

/* Modules */
"module": "es2022", /* Specify what module code is generated. */
"moduleResolution": "bundler", /* Specify how TypeScript looks up a file from a given module specifier. */
"module": "es2022" /* Specify what module code is generated. */,
"moduleResolution": "bundler" /* Specify how TypeScript looks up a file from a given module specifier. */,
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */

/* Emit */
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
"outDir": "./dist" /* Specify an output folder for all emitted files. */,

/* Interop Constraints */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
"strictPropertyInitialization": false, /* Check for class properties that are declared but not set in the constructor. */
"strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
"strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
"alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
"noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
"noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
"noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
"noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
"noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
"noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
"noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
"strict": true /* Enable all strict type-checking options. */,
"strictNullChecks": true /* When type checking, take into account 'null' and 'undefined'. */,
"strictPropertyInitialization": false /* Check for class properties that are declared but not set in the constructor. */,
"strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
"strictBindCallApply": true /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */,
"alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
"noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
"noImplicitReturns": true /* Enable error reporting for codepaths that do not explicitly return in a function. */,
"noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
"noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,
"noImplicitThis": true /* Enable error reporting when 'this' is given the type 'any'. */,
"noUncheckedIndexedAccess": true /* Add 'undefined' to a type when accessed using an index. */,
"noPropertyAccessFromIndexSignature": true /* Enforces using indexed accessors for keys declared using an indexed type. */,
"noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements. */,
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */

/* Completeness */
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */

/* Internal-use: package paths */
@@ -52,6 +52,6 @@

/* Internal-use: running example scripts */
"ts-node": {
"esm": true,
"esm": true
}
}