Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"bin": {
"nullstack": "./scripts/index.js"
},
"types": "./types/index.d.ts",
"dependencies": {
"@babel/plugin-transform-typescript": "^7.16.1",
"typescript": "^4.5.3",
Expand Down
6 changes: 1 addition & 5 deletions tests/src/TypeScript.nts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import Nullstack from 'nullstack';

interface Self {
initiated: boolean
}

interface ClientContext {
self: Self
self: Context['self']
}

class TypeScript extends Nullstack {
Expand Down
13 changes: 13 additions & 0 deletions types/Context/Environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type Environment = {
client: boolean,
server: boolean,
development: boolean,
production: boolean,
static: boolean,
/**
* md5 hash of the current environment folder outputs.
*
* https://nullstack.app/context-environment
*/
key: string
};
73 changes: 73 additions & 0 deletions types/Context/Page.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
type Page = {
/**
* Current page title
*
* https://nullstack.app/context-page
*/
title: string,
/**
* Path to site banner at **public** folder
*
* https://nullstack.app/context-page
*/
image: string,
/**
* Current page description
*
* https://nullstack.app/context-page
*/
description: string,
/**
* Absolute canonical url
*
* https://nullstack.app/context-page
*/
canonical: string,
/**
* Current page locale, example: `en-US`
*
* https://nullstack.app/context-page
*/
locale: string,
/**
* Related to robots.txt file generation
*
* https://nullstack.app/context-page
*/
robots: string,
schema: object,
/**
* Represents the `changefreq` key in the **sitemap.xml**
*
* https://nullstack.app/context-page
*/
changes: 'always'
| 'hourly'
| 'daily'
| 'weekly'
| 'monthly'
| 'yearly'
| 'never',
/**
* Represents the `priority` key in the **sitemap.xml**
*
* sitemaps assume a `0.5` priority
*
* https://nullstack.app/context-page
*/
priority: number,
/**
* The page current HTTP response, example: `200`
*
* https://nullstack.app/context-page
*/
status: number,
/**
* Event raised when `page.title` changes.
*
* Only on client.
*
* https://nullstack.app/context-page#custom-events
*/
event: string
};
42 changes: 42 additions & 0 deletions types/Context/Project.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
type Project = {
domain: string,
/**
* Name of the project
*
* https://nullstack.app/context-project
*/
name: string,
shortName: string,
color: string,
backgroundColor: string,
/**
* Type of the app, example: `website`
*/
type: string,
display: string,
orientation: string,
scope: string,
root: string,
/**
* App icons size/path
*
* If not declared, Nullstack searchs for `icon-[WIDTH]x[HEIGHT].png` in **public** folder
*
* @example { '72': '/icon-72x72.png' }
*/
icons: object,
/**
* Relative or absolute url to favicon
*/
favicon: string,
/**
* Relative paths
*/
disallow: string[],
/**
* If active or relative/absolute url
*/
sitemap: boolean | string,
cdn: string,
protocol: 'http' | 'https',
};
28 changes: 28 additions & 0 deletions types/Context/Router.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
type Router = {
/**
* All url after the domain including the path and the query params
*
* https://nullstack.app/routes-and-params#router
*/
url: string,
/**
* The router path without query params.
*
* https://nullstack.app/routes-and-params#router
*/
path: string,
/**
* Only the base url, example: `https://nullstack.app`
*
* https://nullstack.app/routes-and-params#router
*/
base: string,
/**
* Event raised when `router.url` or `router.path` changes.
*
* Only on client.
*
* https://nullstack.app/routes-and-params#custom-events
*/
event: string
};
16 changes: 16 additions & 0 deletions types/Context/Self.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type Self = {
initiated: boolean,
hydrated: boolean,
prerendered: boolean,
/**
* If the component is persistent
*
* https://nullstack.app/persistent-components
*/
persistent: boolean,
/**
* Only on client
*/
element: HTMLElement,
key: string
};
16 changes: 16 additions & 0 deletions types/Context/Server.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type Server = {
get()
post()
put()
patch()
delete()
options()
head()
use()
port: number,
maximumPayloadSize: string,
/**
* Will be passed as the argument to [express cors plugin](https://expressjs.com/en/resources/middleware/cors.html).
*/
cors: object
};
11 changes: 11 additions & 0 deletions types/Context/UserDefined.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Params = {
[key: string]: string | boolean
};

type Settings = {
[key: string]: string | boolean
};

type Secrets = {
[key: string]: string | boolean
};
23 changes: 23 additions & 0 deletions types/Context/Worker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
type CtxWorker<qType = object> = {
/**
* - keys: server functions names
* - values: array of these functions arguments
*
* https://nullstack.app/service-worker#loading-screens
*/
queues: qType,

/**
* When a server function is called fetching will be set to `true` until the response is resolved.
*
* https://nullstack.app/service-worker#loading-screens
*/
fetching: boolean,

/**
* @deprecated Removed on v0.9.20 use `fetching` instead:
*
* https://nullstack.app/service-worker#loading-screens
*/
loading: boolean
};
137 changes: 137 additions & 0 deletions types/Context/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/// <reference path="./Page.d.ts"/>
/// <reference path="./Project.d.ts"/>
/// <reference path="./Worker.d.ts"/>
/// <reference path="./Self.d.ts"/>
/// <reference path="./Environment.d.ts"/>
/// <reference path="./Server.d.ts"/>
/// <reference path="./UserDefined.d.ts"/>
/// <reference path="./Router.d.ts"/>

/**
* https://nullstack.app/context
*/
type Context = {
/**
* Information about the document `head` metatags.
*
* https://nullstack.app/context-page
*/
page?: Page,

/**
* Information about the app manifest and some metatags.
*
* https://nullstack.app/context-project
*/
project?: Project,

/**
* Gives you granular control of your PWA behavior.
*
* https://nullstack.app/service-worker
*/
worker?: CtxWorker,

/**
* It gives you information about the instance lifecycle and it's unique [key](https://nullstack.app/instance-self#instance-key).
*
* https://nullstack.app/instance-self
*/
self?: Self,

/**
* It gives you information about the element dataset.
*
* Any `data-*` attributes will receive a respective camelized key on this object.
*
* Only on client.
*
* https://nullstack.app/context-data
*/
data?: object,

/**
* It gives you all active instances of the application.
*
* Adding a [key](https://nullstack.app/instance-self#instance-key) to a Component adds it here.
*
* Only on client.
*
* https://nullstack.app/context-instances
*/
instances?: object,

/**
* It gives you information about the current environment.
*
* https://nullstack.app/context-environment
*/
environment?: Environment,

/**
* The server key is a proxy around the [Express](https://expressjs.com/) instance that runs Nullstack under the hood.
*
* Only on server.
*
* https://nullstack.app/server-request-and-response
*/
server?: Server,
/**
* Original `request` object from [Express](https://expressjs.com/)
*
* Only on server.
*
* https://nullstack.app/server-request-and-response
*/
request?: object,
/**
* Original `response` object from [Express](https://expressjs.com/)
*
* Only on server.
*
* https://nullstack.app/server-request-and-response
*/
response?: object,

/**
* Each query string param is mapped to this object.
*
* https://nullstack.app/routes-and-params#params
* @example
* "/?expanded=true&page=2" === {expanded: true, page: 2}
*/
params?: Params,

/**
* Nullstack router.
*
* https://nullstack.app/routes-and-params#router
*/
router?: Router,

/**
* You can assign any key with any type of public information.
*
* .env `NULLSTACK_SETTINGS_PUBLIC_KEY` -> `settings.publicKey`
*
* https://nullstack.app/context-settings
*/
settings?: Settings,

/**
* You can assign any key with any type of private information.
*
* .env `NULLSTACK_SECRETS_PRIVATE_KEY` -> `secrets.privateKey`
*
* https://nullstack.app/context-secrets
*/
secrets?: Secrets,

/**
* Children elements of this component.
*
* https://nullstack.app/renderable-components#components-with-children
*/
children?: any,
[key: string]: any
};
Loading