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

Feat create resources #848

Merged
merged 48 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
2029e8a
feat(cli): Split project creation and pulling
byawitz May 20, 2024
75a01c8
feat(cli): Interactive bucket creation
byawitz May 20, 2024
05df5dd
feat(cli): Interactive messaging-topic creation
byawitz May 20, 2024
01d7bc5
feat(cli): Interactive collection creation
byawitz May 20, 2024
e2e80e6
feat(cli): Interactive questions
byawitz May 20, 2024
d4b2c33
refactor(cli): Function `pull` to `create`
byawitz May 20, 2024
c90817e
chore(cli): Marking as todo
byawitz May 20, 2024
3a47c66
feat(cli): Pulling function code and definition
byawitz May 20, 2024
9c41789
Merge branch 'refs/heads/feat-cli-g2' into feat-split-project-actions
byawitz May 20, 2024
c0766e4
fix(cli): replacing ID import
byawitz May 20, 2024
5e1020a
Merge branch 'refs/heads/feat-create-resources' into feat-pull-function
byawitz May 20, 2024
6f4e994
Merge branch 'refs/heads/feat-adding-messaging' into feat-create-reso…
byawitz May 20, 2024
0a0a671
feat(cli): Interactive topics creation
byawitz May 20, 2024
c0b70a4
Merge branch 'refs/heads/feat-adding-messaging' into feat-split-proje…
byawitz May 20, 2024
5f846b9
Merge branch 'refs/heads/feat-split-project-actions' into feat-create…
byawitz May 20, 2024
f400f39
Merge branch 'refs/heads/feat-cli-g2' into feat-create-resources
byawitz May 21, 2024
69d0eb2
Merge branch 'refs/heads/feat-cli-g2' into feat-split-project-actions
byawitz May 21, 2024
9b71779
Merge branch 'refs/heads/feat-split-project-actions' into feat-create…
byawitz May 21, 2024
b6b810e
Merge branch 'refs/heads/feat-create-resources' into feat-pull-function
byawitz May 21, 2024
60c2bd5
refactor(cli): twig tags
byawitz May 21, 2024
4dd832f
refactor(cli): twig multiple lines
byawitz May 21, 2024
2d8fe79
feat(cli): Init project forces login
byawitz May 21, 2024
abef847
refactor(cli): Refactor message text
byawitz May 22, 2024
b7f278b
Merge branch 'refs/heads/feat-split-project-actions' into feat-create…
byawitz May 22, 2024
634679a
chore(cli): rebasing head
byawitz May 22, 2024
06cecf1
Merge branch 'refs/heads/feat-create-resources' into feat-pull-function
byawitz May 22, 2024
283a063
chore(cli): rebasing head
byawitz May 22, 2024
32ab736
Merge pull request #847 from appwrite/feat-pull-function
christyjacob4 May 22, 2024
f892673
refactor(cli): Omitting the `project` sub-command
byawitz May 22, 2024
43e8895
Merge branch 'refs/heads/feat-split-project-actions' into feat-create…
byawitz May 22, 2024
848e222
refactor(cli): Changing error to info
byawitz May 22, 2024
7015c31
Merge branch 'refs/heads/feat-split-project-actions' into feat-create…
byawitz May 23, 2024
a48c3e2
refactor(cli): Grouping init functionality
byawitz May 23, 2024
2bb8da3
refactor(cli): Project pull to update project name
byawitz May 23, 2024
cd505f3
refactor(cli): Project push to update remote project name
byawitz May 23, 2024
793689e
Merge branch 'refs/heads/feat-cli-g2' into feat-create-resources
byawitz May 24, 2024
bce40e8
feat(cli): Pulling function without questions, and review refactoring
byawitz May 24, 2024
051891b
chore(cli): Allowing the use of `deploy` like `push`
byawitz May 24, 2024
768c4ed
refactor(cli): Changing commands from single to plural when applicable
byawitz May 24, 2024
ca5c806
feat(cli): Creating function from all available templates
byawitz May 24, 2024
7aaa344
Merge pull request #855 from appwrite/chore-backwards-compatibility
christyjacob4 May 27, 2024
e587222
Merge pull request #856 from appwrite/refactor-singular-to-plural
christyjacob4 May 27, 2024
7da50a3
Merge branch 'refs/heads/feat-create-resources' into feat-functions-t…
byawitz May 28, 2024
64726b2
refactor(cli): Review fixing
byawitz May 28, 2024
cf290e2
Merge pull request #857 from appwrite/feat-functions-templates
christyjacob4 May 28, 2024
69f5132
Merge branch 'refs/heads/feat-cli-g2' into feat-create-resources
byawitz May 28, 2024
569a24b
Merge branch 'refs/heads/feat-cli-g2' into feat-create-resources
byawitz May 28, 2024
f0be8ee
Merge branch 'refs/heads/feat-cli-g2' into feat-create-resources
byawitz May 29, 2024
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
5 changes: 5 additions & 0 deletions src/SDK/Language/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ public function getFiles(): array
'destination' => 'lib/utils.js',
'template' => 'cli/lib/utils.js.twig',
],
[
'scope' => 'default',
'destination' => 'lib/commands/init.js',
'template' => 'cli/lib/commands/init.js.twig',
],
[
'scope' => 'default',
'destination' => 'lib/commands/pull.js',
Expand Down
10 changes: 6 additions & 4 deletions templates/cli/base/params.twig
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@
{% endif %}
{% endfor %}
{% if method.type == 'location' %}
payload['project'] = localConfig.getProject().projectId
payload['key'] = globalConfig.getKey();
const queryParams = new URLSearchParams(payload);
apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
if (!overrideForCli) {
payload['project'] = localConfig.getProject().projectId
payload['key'] = globalConfig.getKey();
const queryParams = new URLSearchParams(payload);
apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
}
{% endif %}
13 changes: 8 additions & 5 deletions templates/cli/base/requests/api.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
{% endfor %}
}, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});

{% if method.type == 'location' %}
fs.writeFileSync(destination, response);
{%~ if method.type == 'location' %}
if (overrideForCli) {
response = Buffer.from(response);
}

{% endif %}
fs.writeFileSync(destination, response);
{%~ endif %}
if (parseOutput) {
parse(response)
success()
}
return response;

return response;
2 changes: 2 additions & 0 deletions templates/cli/index.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const { commandDescriptions, cliConfig } = require("./lib/parser");
const { client } = require("./lib/commands/generic");
{% if sdk.test != "true" %}
const { login, logout, whoami } = require("./lib/commands/generic");
const { init } = require("./lib/commands/init");
const { pull } = require("./lib/commands/pull");
const { push } = require("./lib/commands/push");
{% endif %}
Expand All @@ -38,6 +39,7 @@ program
{% if sdk.test != "true" %}
.addCommand(whoami)
.addCommand(login)
.addCommand(init)
.addCommand(pull)
.addCommand(push)
.addCommand(logout)
Expand Down
20 changes: 17 additions & 3 deletions templates/cli/lib/commands/command.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const {{ service.name | caseLower }} = new Command("{{ service.name | caseLower
{% for parameter in method.parameters.all %}
* @property {{ "{" }}{{ parameter | typeName }}{{ "}" }} {{ parameter.name | caseCamel | escapeKeyword }} {{ parameter.description | replace({'`':'\''}) | replace({'\n':' '}) | replace({'\n \n':' '}) }}
{% endfor %}
* @property {boolean} overrideForCli
* @property {boolean} parseOutput
* @property {libClient | undefined} sdk
{% if 'multipart/form-data' in method.consumes %}
Expand All @@ -58,8 +59,21 @@ const {{ service.name | caseLower }} = new Command("{{ service.name | caseLower
/**
* @param {{ "{" }}{{ service.name | caseUcfirst }}{{ method.name | caseUcfirst }}RequestParams{{ "}" }} params
*/
const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {% for parameter in method.parameters.all %}{{ parameter.name | caseCamel | escapeKeyword }}, {% endfor %}parseOutput = true, sdk = undefined{% if 'multipart/form-data' in method.consumes %}, onProgress = () => {}{% endif %}{% if method.type == 'location' %}, destination{% endif %}}) => {
let client = !sdk ? await {% if service.name == "projects" %}sdkForConsole(){% else %}sdkForProject(){% endif %} : sdk;
{%~ block decleration -%}
const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({
{%- for parameter in method.parameters.all -%}
{{ parameter.name | caseCamel | escapeKeyword }},
{%- endfor -%}

{%- block baseParams -%}parseOutput = true, overrideForCli = false, sdk = undefined {%- endblock -%}

{%- if 'multipart/form-data' in method.consumes -%},onProgress = () => {}{%- endif -%}

{%- if method.type == 'location' -%}, destination{%- endif -%}
}) => {
{%~ endblock %}
let client = !sdk ? await {% if service.name == "projects" %}sdkForConsole(){% else %}sdkForProject(){% endif %} :
sdk;
let apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};
{{ include ('cli/base/params.twig') }}
{% if 'multipart/form-data' in method.consumes %}
Expand Down Expand Up @@ -90,4 +104,4 @@ module.exports = {
{{ service.name | caseLower }}{{ method.name | caseUcfirst }}{% if not loop.last %},{% endif %}

{% endfor %}
};
};
106 changes: 55 additions & 51 deletions templates/cli/lib/commands/generic.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,58 @@ const { actionRunner, success, parseBool, commandDescriptions, error, parse, dra
const { questionsLogin, questionsListFactors, questionsMfaChallenge } = require("../questions");
const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");

const loginCommand = async () => {
const answers = await inquirer.prompt(questionsLogin)

let client = await sdkForConsole(false);

await accountCreateEmailPasswordSession({
email: answers.email,
password: answers.password,
parseOutput: false,
sdk: client
})

client.setCookie(globalConfig.getCookie());

let account;

try {
account = await accountGet({
sdk: client,
parseOutput: false
});
} catch(error) {
if (error.response === 'user_more_factors_required') {
const { factor } = await inquirer.prompt(questionsListFactors);

const challenge = await accountCreateMfaChallenge({
factor,
parseOutput: false,
sdk: client
});

const { otp } = await inquirer.prompt(questionsMfaChallenge);

await accountUpdateMfaChallenge({
challengeId: challenge.$id,
otp,
parseOutput: false,
sdk: client
});

account = await accountGet({
sdk: client,
parseOutput: false
});
} else {
throw error;
}
}

success("Signed in as user with ID: " + account.$id);
};

const whoami = new Command("whoami")
.description(commandDescriptions['whoami'])
.option("-j, --json", "Output in JSON format")
Expand Down Expand Up @@ -48,62 +100,13 @@ const whoami = new Command("whoami")
drawTable(data)
}));


const login = new Command("login")
.description(commandDescriptions['login'])
.configureHelp({
helpWidth: process.stdout.columns || 80
})
.action(actionRunner(async () => {
const answers = await inquirer.prompt(questionsLogin)

let client = await sdkForConsole(false);

await accountCreateEmailPasswordSession({
email: answers.email,
password: answers.password,
parseOutput: false,
sdk: client
})

client.setCookie(globalConfig.getCookie());

let account;

try {
account = await accountGet({
sdk: client,
parseOutput: false
});
} catch (error) {
if (error.response === 'user_more_factors_required') {
const { factor } = await inquirer.prompt(questionsListFactors);

const challenge = await accountCreateMfaChallenge({
factor,
parseOutput: false,
sdk: client
});

const { otp } = await inquirer.prompt(questionsMfaChallenge);

await accountUpdateMfaChallenge({
challengeId: challenge.$id,
otp,
parseOutput: false,
sdk: client
});

account = await accountGet({
sdk: client,
parseOutput: false
});
} else {
throw error;
}
}

success("Signed in as user with ID: " + account.$id);
}));
.action(actionRunner(loginCommand));

const logout = new Command("logout")
.description(commandDescriptions['logout'])
Expand Down Expand Up @@ -199,6 +202,7 @@ const client = new Command("client")

module.exports = {
{% if sdk.test != "true" %}
loginCommand,
whoami,
login,
logout,
Expand Down
Loading